2
0

Simplified reconnecting wifi smart socket

This commit is contained in:
Harald Rietman
2017-11-10 21:30:46 +01:00
parent ab7ea0413c
commit 47c9a58b54
2 changed files with 9 additions and 18 deletions

View File

@@ -58,7 +58,7 @@ module.exports = function(RED) {
node.on('close', function (done) { node.on('close', function (done) {
if (retryTimer) { if (retryTimer) {
clearInterval(retryTimer); clearTimeout(retryTimer);
} }
if (delayedStatusMsgTimer) { if (delayedStatusMsgTimer) {
clearTimeout(delayedStatusMsgTimer); clearTimeout(delayedStatusMsgTimer);
@@ -132,7 +132,6 @@ module.exports = function(RED) {
connectionState = "connected"; connectionState = "connected";
delayedStatusMsgUpdate(); delayedStatusMsgUpdate();
} }
watchdog();
}) })
.catch(function (error) { .catch(function (error) {
connectionState = "reconnecting"; connectionState = "reconnecting";
@@ -140,28 +139,20 @@ module.exports = function(RED) {
node.plug.destroy(); node.plug.destroy();
node.plug = null; node.plug = null;
} }
watchdog();
}) })
}; };
var watchdog = function() { var watchdog = function() {
console.log("retrytimer started"); setTimeout(function retryTimer() {
var interval = 10; discoverDevice();
retryTimer = setInterval(function() { if (connectionState === "reconnecting") {
if (interval == 0) { node.status({fill: "red", shape: "dot", text: "reconnecting"});
interval = 10;
clearInterval(retryTimer);
discoverDevice();
} else {
interval--;
if (connectionState === "reconnecting") {
node.status({fill: "red", shape: "dot", text: "retrying in " + interval + " sec."});
}
} }
}, 1000); setTimeout(retryTimer, 30000);
}, 30000);
} }
} }
RED.nodes.registerType("xiaomi-plug-wifi", XiaomiPlugWifiNode); RED.nodes.registerType("xiaomi-plug-wifi", XiaomiPlugWifiNode);
process.on('unhandledRejection', function(reason, p) { process.on('unhandledRejection', function(reason, p) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-xiaomi-devices", "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.", "description": "A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway.",
"repository": { "repository": {
"type": "git", "type": "git",