From ba1eca82eb0667b514eb3c3df512e84ac25a11d3 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Tue, 7 May 2019 21:00:17 +0200 Subject: [PATCH] Reenable joining after 200 seconds. https://github.com/Koenkk/zigbee2mqtt/issues/1429 #1445 --- lib/zigbee.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/zigbee.js b/lib/zigbee.js index ee8f9298..4fc0ca17 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -45,6 +45,7 @@ class Zigbee { this.onMessage = this.onMessage.bind(this); this.onError = this.onError.bind(this); this.messageHandler = null; + this.permitJoinTimer = null; this.queue = new ZigbeeQueue(); } @@ -130,6 +131,10 @@ class Zigbee { } stop(callback) { + if (this.permitJoinTimer) { + clearInterval(this.permitJoinTimer); + } + this.queue.stop(); // Backup coordinator @@ -176,6 +181,24 @@ class Zigbee { logger.info('Zigbee: disabling joining new devices.'); } + // In zigbee 3.0 a network automatically closes after 254 seconds. + // As a workaround, we enable joining again. + if (this.permitJoinTimer) { + clearInterval(this.permitJoinTimer); + } + + if (permit) { + this.permitJoinTimer = setInterval(() => { + this.shepherd.permitJoin(255, (error) => { + if (error) { + logger.error('Failed to reenable joining'); + } else { + logger.info('Succesfully reenabled joining'); + } + }); + }, utils.secondsToMilliseconds(200)); + } + this.shepherd.permitJoin(permit ? 255 : 0, (error) => { if (error) { logger.info(error);