Commit e908ea8a by Chavee Issariyapat

clean up debug log

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