Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.connect = function(host, port, callback) {
console.log("MQTT Connecting to %s:%s", host || exports.argv.brokerHost, port || exports.argv.brokerPort );
mqtt.createClient(port || exports.argv.brokerPort, host || exports.argv.brokerHost, function(err, client) {
if (err) {
console.log('MQTT %s', err);
process.exit(1);
}
exports.mqttClient = client;
client.connect({keepalive: 40000});
client.on('connack', function(packet) {
if (packet.returnCode === 0) {
setInterval(function() {client.pingreq();}, 30000);
exports.events.emit('connected', packet);
} else {
console.log('MQTT Connack error %d', packet.returnCode);
process.exit(-1);
}