From 47c9a58b54682077d18f4e79ff674cc7300b762f Mon Sep 17 00:00:00 2001 From: Harald Rietman Date: Fri, 10 Nov 2017 21:30:46 +0100 Subject: [PATCH] Simplified reconnecting wifi smart socket --- .../xiaomi-socket-wifi.js | 25 ++++++------------- package.json | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js b/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js index 825a852..55ebf58 100644 --- a/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js +++ b/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js @@ -58,7 +58,7 @@ module.exports = function(RED) { node.on('close', function (done) { if (retryTimer) { - clearInterval(retryTimer); + clearTimeout(retryTimer); } if (delayedStatusMsgTimer) { clearTimeout(delayedStatusMsgTimer); @@ -132,7 +132,6 @@ module.exports = function(RED) { connectionState = "connected"; delayedStatusMsgUpdate(); } - watchdog(); }) .catch(function (error) { connectionState = "reconnecting"; @@ -140,28 +139,20 @@ module.exports = function(RED) { node.plug.destroy(); node.plug = null; } - watchdog(); }) }; var watchdog = function() { - console.log("retrytimer started"); - var interval = 10; - retryTimer = setInterval(function() { - if (interval == 0) { - interval = 10; - clearInterval(retryTimer); - discoverDevice(); - } else { - interval--; - if (connectionState === "reconnecting") { - node.status({fill: "red", shape: "dot", text: "retrying in " + interval + " sec."}); - } + setTimeout(function retryTimer() { + discoverDevice(); + if (connectionState === "reconnecting") { + node.status({fill: "red", shape: "dot", text: "reconnecting"}); } - }, 1000); + setTimeout(retryTimer, 30000); + }, 30000); } - } + RED.nodes.registerType("xiaomi-plug-wifi", XiaomiPlugWifiNode); process.on('unhandledRejection', function(reason, p) { diff --git a/package.json b/package.json index 3496ed6..ca7f627 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-xiaomi-devices", - "version": "1.0.13", + "version": "1.0.14", "description": "A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway.", "repository": { "type": "git",