Commit e908ea8a by Chavee Issariyapat

clean up debug log

parent 86365c21
module.exports.create = create
const DEBUG_SUBLIST = true;
const DEBUG_SUBLIST = false;
const events = require('events');
const cache = require('./cache');
......@@ -165,72 +165,44 @@ const Coordinator = function(param={}) {
});
this.remoteclient.on('message', function(topic, payload){
console.log("Incoming MQTT message-------------------------------------------------");
console.log({
topic,
payload: payload.toString()
})
let jsonpayload = {};
try {
jsonpayload = JSON.parse(payload.toString());
}
catch(e) {}
if (topic.startsWith('@shadow/data/updated')) {
let newpayload = cache.mergeShadow(jsonpayload.deviceid, jsonpayload);
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/merged`, JSON.stringify(newpayload) );
// that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/updated`, JSON.stringify(jsonpayload) );
that.flowemitter.pub(`flow:shadow:${jsonpayload.deviceid}`, {
// shadowupdated : JSON.stringify(jsonpayload),
// shadowmerged : JSON.stringify(newpayload)
shadowupdated : jsonpayload,
shadowmerged : newpayload
});
}
else if (topic.startsWith('@device/status/changed')){
cache.setStatus(jsonpayload.deviceid, jsonpayload);
//that.flowemitter.publish(`${jsonpayload.deviceid}/device/changed`, JSON.stringify(jsonpayload));
that.flowemitter.pub(`flow:device:${jsonpayload.deviceid}`, {
//devicechanged : JSON.stringify(jsonpayload)
devicechanged : jsonpayload
});
}
else if (topic.startsWith('@private/shadow/data/get/response')){
cache.setShadow(jsonpayload.deviceid, jsonpayload);
//that.flowemitter.publish(`${jsonpayload.deviceid}/shadow/get`, JSON.stringify(jsonpayload));
that.flowemitter.pub(`flow:shadow:${jsonpayload.deviceid}`, {
//shadowget : JSON.stringify(jsonpayload)
shadowget : jsonpayload
});
}
else if (topic.startsWith('@private/device/status/get/response')){
cache.setStatus(jsonpayload.deviceid, jsonpayload);
//that.flowemitter.publish(`${jsonpayload.deviceid}/device/get`, JSON.stringify(jsonpayload));
that.flowemitter.pub(`flow:device:${jsonpayload.deviceid}`, {
//deviceget : JSON.stringify(jsonpayload)
deviceget : jsonpayload
});
}
else if (topic.startsWith('@msg/')) {
// let part = topic.split('/').splice(1).join('/');
// let localtopic = `@msg/${part}`;
that.flowemitter.pub(`flow:msg`, {
topic: topic,
payload: payload
});
// that.flowemitter.publish(`msg:${localtopic}`, {
// msg : {
// localtopic,
// payload
// }
// });
}
});
......
......@@ -20,10 +20,6 @@ let FlowAgent = function(option = {}) {
red : option.red || null
}
// if (!this.option.red.flowevents) {
// this.option.red.flowevents = new events.EventEmitter;
// }
this.remoteclient = MQTTClient.create({
host: that.option.broker_uri,
options: {
......@@ -34,15 +30,6 @@ let FlowAgent = function(option = {}) {
}
});
// console.log({
// host: that.option.broker_uri,
// options: {
// clientId: Date.now()+'-'+that.option.flowagentid,
// username: that.option.flowagentid,
// password: that.option.flowagentsecret,
// keepalive: 30
// }});
this.flowemitter = FlowEmitter.create({red: this.option.red});
this.coordinator = Coordinatior.create({
remoteclient: that.remoteclient,
......@@ -50,8 +37,6 @@ let FlowAgent = function(option = {}) {
});
}
//FlowAgent.prototype = new events.EventEmitter;
FlowAgent.prototype.on = function(eventname, handler) {
this.on(eventname, handler);
}
......
......@@ -64,4 +64,3 @@ MQTTClient.prototype.unsubscribe = function(topic) {
function create(param) {
return new MQTTClient(param);
}
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