Commit 9c029cc7 by Chavee Issariyapat

add working flowagent with debug log

parent 90979b08
......@@ -56,6 +56,19 @@ const Coordinator = function(param={}) {
}
});
this.localserver.on('clientSubscribed', function(packet, client) {
let deviceid = client.id.split(':')[0];
// if client try to subscribe @msg/xxx/yyy --> flowagent subscribe @tap on a remote broker
if (packet.topic.startsWith('@msg/')) {
let msgpart = packet.topic.split('/').splice(3).join('/');
outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${msgpart}`;
that.remoteclient.subscribe(outtopic);
}
else {
}
});
this.localserver.on('clientPublished', function(packet, client){
console.log('client published', client.id);
......@@ -78,6 +91,13 @@ const Coordinator = function(param={}) {
outmsg = packet.payload.toString();
that.remoteclient.publish(outtopic, outmsg);
break;
default:
if (packet.topic.startsWith('@msg/')) {
let part = packet.topic.substr(5);
outtopic = `@tap/msg/topic/${deviceid}:${client.token}/${part}`;
outmsg = packet.payload.toString();
that.remoteclient.publish(outtopic, outmsg);
}
}
});
......@@ -123,6 +143,12 @@ const Coordinator = function(param={}) {
cache.setStatus(jsonpayload.deviceid, jsonpayload);
that.localserver.publish(`${jsonpayload.deviceid}/device/get`, JSON.stringify(jsonpayload));
}
else if (topic.startsWith('@msg/')) {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
console.log({topic, payload})
that.localserver.publish(topic, payload);
}
});
}
......
......@@ -39,7 +39,7 @@ MQTTServer.prototype.start = function() {
that.emit('clientSubscribed',{
deviceid: client.id,
topic: topic
});
}, client);
});
this.mqttserver.on('unsubscribed', function(topic, client) {
......
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