Commit 0df933eb by Chavee Issariyapat

update

parent fc675c76
...@@ -26,13 +26,17 @@ const Coordinator = function(param={}) { ...@@ -26,13 +26,17 @@ const Coordinator = function(param={}) {
jsonpayload = JSON.parse(payload.toString()); jsonpayload = JSON.parse(payload.toString());
} }
catch(e) {} catch(e) {}
that.localserver.publish(`${jsonpayload.deviceid}/devicestatus`, payload.toString());
});
if (topic == '@shadow/data/updated') {
that.localserver.publish(`${jsonpayload.deviceid}/shadow`, payload.toString());
}
else if (topic.startsWith('@device/status/changed')){
that.localserver.publish(`${jsonpayload.deviceid}/device`, payload.toString());
}
});
} }
Coordinator.prototype = new events.EventEmitter; Coordinator.prototype = new events.EventEmitter;
Coordinator.prototype.start = function() { Coordinator.prototype.start = function() {
this.remoteclient.connect(); this.remoteclient.connect();
this.localserver.start(); this.localserver.start();
......
...@@ -45,9 +45,7 @@ MQTTServer.prototype.start = function() { ...@@ -45,9 +45,7 @@ MQTTServer.prototype.start = function() {
}); });
} }
MQTTServer.prototype.publish = function(topic, payload) { MQTTServer.prototype.publish = function(topic, payload) {
let msgobj = { let msgobj = {
topic : topic, topic : topic,
payload : payload, payload : payload,
...@@ -56,8 +54,7 @@ MQTTServer.prototype.publish = function(topic, payload) { ...@@ -56,8 +54,7 @@ MQTTServer.prototype.publish = function(topic, payload) {
} }
this.mqttserver.publish(msgobj, function(){ this.mqttserver.publish(msgobj, function(){
console.log({topic, payload}) //console.log({topic, payload})
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment