Skip to content

Commit

Permalink
Reenable joining after 200 seconds. #1429 #1445
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed May 7, 2019
1 parent 68d2d0a commit 2ba62ed
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/zigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -130,6 +131,10 @@ class Zigbee {
}

stop(callback) {
if (this.permitJoinTimer) {
clearInterval(this.permitJoinTimer);
}

this.queue.stop();

// Backup coordinator
Expand Down Expand Up @@ -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(3));
}

this.shepherd.permitJoin(permit ? 255 : 0, (error) => {
if (error) {
logger.info(error);
Expand Down

0 comments on commit 2ba62ed

Please sign in to comment.