Commit 573dd9df by Chavee Issariyapat

update

parent 01463e11
...@@ -3,15 +3,23 @@ module.exports.create = create ...@@ -3,15 +3,23 @@ module.exports.create = create
const events = require('events'); const events = require('events');
const Coordinator = function(param={}) { const Coordinator = function(param={}) {
let that = this;
console.log(param)
this.remoteclient = param.remoteclient; this.remoteclient = param.remoteclient;
this.localserver = param.localserver; this.localserver = param.localserver;
this.localserver.on('client_subscribe', function(data){ this.localserver.on('client_subscribe', function(data){
console.log('client subscribe', data.deviceid, data.topic); console.log('client subscribe', data.deviceid, data.topic);
that.remoteclient.subscribe('@shadow/data/updated/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96');
that.remoteclient.subscribe('@device/status/changed/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96');
}); });
this.localserver.on('client_unsubscribe', function(data){ this.localserver.on('client_unsubscribe', function(data){
console.log('client unsubscribe', data.deviceid, data.topic); console.log('client unsubscribe', data.deviceid, data.topic);
that.remoteclient.unsubscribe('@shadow/data/updated/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96');
that.remoteclient.unsubscribe('@device/status/changed/+/+/99a7e50a-d9e3-49c4-a7f0-f09b670ebf96');
}); });
} }
......
...@@ -3,13 +3,10 @@ require('dotenv').config(); ...@@ -3,13 +3,10 @@ require('dotenv').config();
const config = require('config'); const config = require('config');
const localBrokerURI = require('url').parse(config.get('config.local_broker_uri')); const localBrokerURI = require('url').parse(config.get('config.local_broker_uri'));
console.log(localBrokerURI)
const MQTTClient = require('./mqttclient'); const MQTTClient = require('./mqttclient');
const MQTTServer = require('./mqttserver'); const MQTTServer = require('./mqttserver');
const Coordinatior = require('./coordinator'); const Coordinatior = require('./coordinator');
let remoteclient = MQTTClient.create({ let remoteclient = MQTTClient.create({
host: config.get('config.remote_broker_uri'), host: config.get('config.remote_broker_uri'),
options: { options: {
...@@ -25,14 +22,5 @@ let localserver = MQTTServer.create({ ...@@ -25,14 +22,5 @@ let localserver = MQTTServer.create({
port : parseInt(localBrokerURI.port) || 1883 port : parseInt(localBrokerURI.port) || 1883
}); });
// localserver.on('client_subscribe', function(data){
// console.log('client subscribe', data.deviceid, data.topic);
// });
// localserver.on('client_unsubscribe', function(data){
// console.log('client unsubscribe', data.deviceid, data.topic);
// });
let coordinatior = Coordinatior.create({remoteclient, localserver}); let coordinatior = Coordinatior.create({remoteclient, localserver});
coordinatior.start(); coordinatior.start();
...@@ -33,7 +33,21 @@ MQTTClient.prototype.connect = function() { ...@@ -33,7 +33,21 @@ MQTTClient.prototype.connect = function() {
} }
MQTTClient.prototype.publish = function(topic, payload) { MQTTClient.prototype.publish = function(topic, payload) {
if (this.client) {
this.client.publish(topic, payload); this.client.publish(topic, payload);
}
else {
}
}
MQTTClient.prototype.subscribe = function(topic) {
if (this.client) {
this.client.subscribe(topic);
}
else {
}
} }
......
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