diff --git a/lib/extension/networkMap.js b/lib/extension/networkMap.js index 8c3cef514..3fafd442a 100644 --- a/lib/extension/networkMap.js +++ b/lib/extension/networkMap.js @@ -11,6 +11,7 @@ class NetworkMap { // Subscribe to topic. this.topic = `${settings.get().mqtt.base_topic}/bridge/networkmap`; + this.topicRoutes = `${settings.get().mqtt.base_topic}/bridge/networkmap/routes`; // Bind this.raw = this.raw.bind(this); @@ -31,13 +32,15 @@ class NetworkMap { onMQTTConnected() { this.mqtt.subscribe(this.topic); + this.mqtt.subscribe(this.topicRoutes); } onMQTTMessage(topic, message) { message = message.toString(); - - if (topic === this.topic && this.supportedFormats.hasOwnProperty(message)) { - this.zigbee.networkScan((result)=> { + const includeRoutes = (topic === this.topicRoutes) ? 1: 0; + if ((topic === this.topic || topic === this.topicRoutes) + && this.supportedFormats.hasOwnProperty(message)) { + this.zigbee.networkScan(includeRoutes, (result)=> { const converted = this.supportedFormats[message](this.zigbee, result); this.mqtt.publish(`bridge/networkmap/${message}`, converted, {}); }); diff --git a/lib/zigbee.js b/lib/zigbee.js index b9c3bc7f8..ded449c48 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -308,8 +308,8 @@ class Zigbee { return (friendlyName ? friendlyName : ID); } - networkScan(callback) { - logger.info('Starting network scan...'); + networkScan(includeRoutes, callback) { + logger.info(`Starting network scan includeRoutes='${includeRoutes}'...`); const lqiScanList = new Set(); const rtgScanList = new Set(); const linkMap = []; @@ -374,7 +374,7 @@ class Zigbee { }); // Remove from scan list and if both lists are done return the completed network map lqiScanList.delete(targetIeeeAddr); - if (lqiScanList.size === 0 && rtgScanList === 0) { + if (lqiScanList.size === 0 && rtgScanList.size === 0) { logger.info('Network scan completed'); collateMap(); } else { @@ -436,14 +436,16 @@ class Zigbee { queueCallback(error); }); }); - rtgScanList.add(dev.ieeeAddr); - this.queue.push(dev.ieeeAddr, (queueCallback) => { - this.shepherd.controller.request('ZDO', 'mgmtRtgReq', {dstaddr: dev.nwkAddr, startindex: 0}, - (error, rsp, ieeeAddr, nwkAddr) => { - processRtgResponse(error, rsp, dev.ieeeAddr, dev.nwkAddr); - queueCallback(error); - }); - }); + if (includeRoutes) { + rtgScanList.add(dev.ieeeAddr); + this.queue.push(dev.ieeeAddr, (queueCallback) => { + this.shepherd.controller.request('ZDO', 'mgmtRtgReq', {dstaddr: dev.nwkAddr, startindex: 0}, + (error, rsp, ieeeAddr, nwkAddr) => { + processRtgResponse(error, rsp, dev.ieeeAddr, dev.nwkAddr); + queueCallback(error); + }); + }); + } }); // Wait for all device scans before forcing map with whatever results are already in