Commit 479776e2 by Chavee Issariyapat

update config

parent 5e466683
{ {
"config" : { "config" : {
"broker_uri" : "BROKER_URI", "remote_broker_uri" : "REMOTE_BROKER_URI",
"local_broker_uri" : "LOCAL_BROKER_URI",
"flowagent_id" : "FLOWAGENT_ID", "flowagent_id" : "FLOWAGENT_ID",
"flowagent_username" : "FLOWAGENT_USERNAME", "flowagent_username" : "FLOWAGENT_USERNAME",
"flowagent_password" : "FLOWAGENT_PASSWORD" "flowagent_password" : "FLOWAGENT_PASSWORD"
......
require('dotenv').config(); require('dotenv').config();
const config = require('config'); const config = require('config');
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');
let mqttclient = MQTTClient.create({ let mqttclient = MQTTClient.create({
host: config.get('config.broker_uri'), host: config.get('config.remote_broker_uri'),
options: { options: {
clientId: config.get('config.flowagent_id'), clientId: config.get('config.flowagent_id'),
username: config.get('config.flowagent_username'), username: config.get('config.flowagent_username'),
...@@ -13,4 +19,12 @@ let mqttclient = MQTTClient.create({ ...@@ -13,4 +19,12 @@ let mqttclient = MQTTClient.create({
} }
}); });
let mqttserver = MQTTServer.create({
host : localBrokerURI.hostname || '0.0.0.0',
port : parseInt(localBrokerURI.port) || 1883
});
mqttclient.connect(); mqttclient.connect();
mqttserver.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