node-red-contrib-barco-sources-here
Version:
utility to get map information using here map
40 lines (37 loc) • 1.11 kB
JavaScript
;
let _client = null;
module.exports = {
publishEvent: function(basePath, callback){
const mqtt = require('mqtt');
let url = `mqtt://${process.env.MQTT_BROKER}:${process.env.MQTT_PORT}`;
//dev purposes
//let url = 'mqtt://10.51.49.122:10101';
let options = {
clientId: 'notification_' + ( 1+ Math.random()*4294967295).toString(16),
username: 'barco',
password: 'b4rc0,BCD',
keepalive: 6,
reconnectPeriod: 1000,
clean: true
};
_client = mqtt.connect(url,options);
_client.on('connect', function () {
//_client.subscribe('/com/barco/analytics/map/bing');
_client.publish('/com/barco/analytics/map/here', basePath+'/incidents/here');
callback();
});
_client.on('message', function (topic, message) {
console.log("Received message from " + topic+ ":: message: "+message);
});
_client.on('error', function (err) {
console.log("Error is connecting : "+url, err);
callback(err);
});
},
closeConnection: function(callback){
if(_client!=null){
_close.end();
_client = null;
}
}
}