Commit 73d12a3b by Chavee Issariyapat

rename tap topic

parent beead226
...@@ -34,8 +34,8 @@ const Coordinator = function(param={}) { ...@@ -34,8 +34,8 @@ const Coordinator = function(param={}) {
let deviceid = client.id.split(':')[0]; let deviceid = client.id.split(':')[0];
if (that.localserver.sublist[deviceid].count <= 1) { if (that.localserver.sublist[deviceid].count <= 1) {
that.remoteclient.unsubscribe(`->tap/shadow/${deviceid}:${client.token}`); that.remoteclient.unsubscribe(`@tap/shadow/${deviceid}:${client.token}`);
that.remoteclient.unsubscribe(`->tap/device/${deviceid}:${client.token}`); that.remoteclient.unsubscribe(`@tap/device/${deviceid}:${client.token}`);
delete that.localserver.sublist[deviceid]; delete that.localserver.sublist[deviceid];
} }
else { else {
...@@ -43,12 +43,22 @@ const Coordinator = function(param={}) { ...@@ -43,12 +43,22 @@ const Coordinator = function(param={}) {
} }
}); });
this.localserver.on('clientPublished', function(packet, client){
console.log('client published', client.id);
let tap_topic = `@tap/shadow/${client.id}:${client.token}`;
let msg = packet.payload.toString();
that.remoteclient.publish(packet.topic, msg)
});
this.remoteclient.on('connect', function() { this.remoteclient.on('connect', function() {
setTimeout(function() { setTimeout(function() {
for (let deviceid in that.localserver.sublist) { for (let deviceid in that.localserver.sublist) {
//console.log(deviceid, that.localserver.sublist[deviceid]) //console.log(deviceid, that.localserver.sublist[deviceid])
that.remoteclient.subscribe(`->tap/shadow/${deviceid}:${that.localserver.sublist[deviceid].token}`); that.remoteclient.subscribe(`@tap/shadow/${deviceid}:${that.localserver.sublist[deviceid].token}`);
that.remoteclient.subscribe(`->tap/device/${deviceid}:${that.localserver.sublist[deviceid].token}`); that.remoteclient.subscribe(`@tap/device/${deviceid}:${that.localserver.sublist[deviceid].token}`);
} }
}, 2000); }, 2000);
}); });
......
...@@ -48,6 +48,14 @@ MQTTServer.prototype.start = function() { ...@@ -48,6 +48,14 @@ MQTTServer.prototype.start = function() {
topic: topic topic: topic
}); });
}); });
this.mqttserver.on('published', function(packet, client) {
// broker itself also publishes as well but without client object
if (client) {
that.emit('clientPublished',packet, client);
}
});
} }
MQTTServer.prototype.publish = function(topic, payload) { MQTTServer.prototype.publish = function(topic, payload) {
......
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
"scripts": { "scripts": {
"start": "node index.js" "start": "node index.js"
}, },
"repository": { "author": "NEXPIE Company Limited (https://nexpie.com)"
"type": "git",
"url": "https://dev.nexpie.com/node-red/flowagent"
},
"author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"config": "^3.2.4", "config": "^3.2.4",
......
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