Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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++;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement