Commit 689cf194 by Chavee Issariyapat

update but still not working

parent 20e8460a
......@@ -9,8 +9,10 @@ const Coordinator = function(param={}) {
let that = this;
this.remoteclient = param.remoteclient;
this.localserver = param.localserver;
// this.localserver = param.localserver || null;
this.flowemitter = param.flowemitter;
/*
this.localserver.on('clientConnected', function(client){
console.log('client connected', client.id);
let deviceid = client.id.split(':')[0];
......@@ -147,12 +149,14 @@ const Coordinator = function(param={}) {
that.localserver.publish(localtopic, payload);
}
});
*/
}
Coordinator.prototype = new events.EventEmitter;
Coordinator.prototype.start = function() {
this.remoteclient.connect();
this.localserver.start();
//this.localserver.start();
this.flowemitter.start();
}
function create(param) {
......
module.exports.create = create
const MQTTClient = require('./mqttclient');
const MQTTServer = require('./mqttserver');
const FlowEmitter = require('./flowemitter');
const Coordinatior = require('./coordinator');
const events = require('events');
let FlowAgent = function(options) {
let that = this;
const FlowAgent = function(option = {}) {
let that = this;
this.option = {
broker_uri : option.broker_uri,
flowagentid : option.flowagentid,
flowagentsecret : option.flowagentsecret
}
this.context = option.context;
this.remoteclient = MQTTClient.create({
host: options.remote_broker_uri,
host: that.option.broker_uri,
options: {
clientId: options.flowagent_id,
username: options.flowagent_username,
password: options.flowagent_password,
clientId: Date.now()+'-'+that.option.flowagentid,
username: that.option.flowagentid,
password: that.option.flowagentsecret,
keepalive: 30
}
});
this.flowemitter = FlowEmitter.create();
this.localserver = MQTTServer.create({
host : options.localBrokerURI.hostname || '0.0.0.0',
port : parseInt(options.localBrokerURI.port) || 1883
this.coordinatior = Coordinatior.create({
remoteclient: that.remoteclient,
flowemitter: that.flowemitter
});
this.coordinatior = Coordinatior.create({remoteclient: that.remoteclient, localserver: that.localserver});
}
FlowAgent.prototype = new events.EventEmitter;
FlowAgent.prototype.start = function() {
this.coordinatior.start();
this.coordinatior.start();
}
function create(options) {
return FlowAgent(options);
function create() {
return new FlowAgent();
}
module.exports.create = create
const events = require('events');
const FlowEmitter = function(param = {}) {
this.sublist = {};
this.globalcontext = param.globalcontext;
}
FlowEmitter.prototype = new events.EventEmitter;
FlowEmitter.prototype.start = function() {
let that = this;
}
// a method for ndoe-red block to register
FlowEmitter.prototype.register = function(deviceid, devicetoken) {
let that = this;
}
FlowEmitter.prototype.deregister = function(deviceid) {
let that = this;
}
function create() {
return new FlowEmitter();
}
require('dotenv').config();
const config = require('config');
const localBrokerURI = require('url').parse(config.get('config.local_broker_uri'));
/*
module.exports.create = create
const MQTTClient = require('./mqttclient');
const MQTTServer = require('./mqttserver');
const FlowEmitter = require('./flowemitter');
const Coordinatior = require('./coordinator');
let remoteclient = MQTTClient.create({
host: config.get('config.remote_broker_uri'),
options: {
clientId: config.get('config.flowagent_id'),
username: config.get('config.flowagent_username'),
password: config.get('config.flowagent_password'),
keepalive: 30
const events = require('events');
const FlowAgent = function(option = {}) {
let that = this;
let this.option = {
broker_uri : option.broker_uri,
flowagentid : option.flowagentid,
flowagentsecret : option.flowagentsecret
}
});
let localserver = MQTTServer.create({
host : localBrokerURI.hostname || '0.0.0.0',
port : parseInt(localBrokerURI.port) || 1883
});
this.context = option.context;
this.remoteclient = MQTTClient.create({
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();
this.coordinatior = Coordinatior.create({
remoteclient: that.remoteclient,
flowemitter: that.flowemitter
});
}
FlowAgent.prototype = new events.EventEmitter;
FlowAgent.prototype.start = function() {
this.coordinatior.start();
}
let coordinatior = Coordinatior.create({remoteclient, localserver});
coordinatior.start();
function create() {
return new FlowAgent();
}
*/
\ No newline at end of file
......@@ -2,9 +2,9 @@
"name": "flowagent",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "flowagent.js",
"scripts": {
"start": "node index.js"
"start": "node run.js"
},
"author": "NEXPIE Company Limited (https://nexpie.com)",
"license": "ISC",
......
require('dotenv').config();
const config = require('config');
const localBrokerURI = require('url').parse(config.get('config.local_broker_uri'));
const flowagent = require('./FlowAgent').create({
broker_uri : config.get('config.remote_broker_uri'),
flowagentid: config.get('config.flowagent_username'),
flowagentsecret: config.get('config.flowagent_password'),
mqttenabled : true
});
flowagent.start();
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