diff --git a/lib/zigbee.js b/lib/zigbee.js index ee8f92982e..4fc0ca1770 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);