Skip to content

Instantly share code, notes, and snippets.

@muka
Created Oct 26, 2016
Embed
What would you like to do?
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://localhost:1883', {
username: "admin",
password: "eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNDc3NDg1NDc5OTEzLCJleHAiOjE0Nzc0ODcyNzksInV1aWQiOiI2NmVkNDc3Mi0wNDg5LTRlOTYtYmI2NS01NDhiMmVkMmM3MWQifQ.LbOAr8pPApDlVBLi32JWtCjmCa80ByAJYq9BnTnWQgh4SWka4WzykMU0D_atE5tYtgICj2QOg-OFglv2ZqLLNw",
protocolId: 'MQTT',
protocolVersion: 4,
});
client.on('connect', function () {
console.log('connected');
client.subscribe("foobar/#");
});
client.on("close", function () {
console.log("disconnected");
});
client.on("error", function (err) {
console.log("error: %j", err);
});
var i = 0;
client.on('message', function (topic, message) {
console.log("\n%s) %s : %s", i, topic, message.toString());
i++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment