How to use mqttjs - 1 common examples

To help you get started, we’ve selected a few mqttjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github binarybucks / homA / tools / lib / node / homa-mqttjs / index.js View on Github external
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);
        }

mqttjs

Deprecated - see mqtt instead

BSD
Latest version published 12 years ago

Package Health Score

66 / 100
Full package analysis

Popular mqttjs functions