Network map routes selectable by mqtt topic (#1736)

This commit is contained in:
clockbrain
2019-07-15 20:02:56 +02:00
committed by Koen Kanters
parent 31b8352f5a
commit 3ae2d2b946
2 changed files with 19 additions and 14 deletions
+6 -3
View File
@@ -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, {});
});
+13 -11
View File
@@ -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