Last active
September 24, 2018 16:31
-
-
Save chrvadala/b0925d95c1927edaf2169d80c60e2726 to your computer and use it in GitHub Desktop.
mqtt connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* usage node connect.js mqtt://localhost:1883 | |
*/ | |
const mqtt = require('mqtt') | |
const URI = process.argv[2] | |
const EVENTS = ['connect', 'reconnect', 'close', 'offline', 'end', 'error', 'packetsend', 'packetreceive', 'message'] | |
console.log('CONNECTING', URI) | |
let client = mqtt.connect( | |
URI, | |
{keepalive: 120 + Math.round(Math.random() * 100)} | |
) | |
EVENTS.forEach(eventName => { | |
client.on(eventName, data => console.log(eventName, JSON.stringify(data))) | |
}) | |
client.subscribe('#') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment