Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. var mqtt = require('mqtt');
  2.  
  3. var client = mqtt.connect('mqtt://localhost:1883', {
  4. username: "admin",
  5. password: "eyJhbGciOiJIUzUxMiJ9.eyJjcmVhdGVkIjoxNDc3NDg1NDc5OTEzLCJleHAiOjE0Nzc0ODcyNzksInV1aWQiOiI2NmVkNDc3Mi0wNDg5LTRlOTYtYmI2NS01NDhiMmVkMmM3MWQifQ.LbOAr8pPApDlVBLi32JWtCjmCa80ByAJYq9BnTnWQgh4SWka4WzykMU0D_atE5tYtgICj2QOg-OFglv2ZqLLNw",
  6. protocolId: 'MQTT',
  7. protocolVersion: 4,
  8. });
  9.  
  10. client.on('connect', function () {
  11. console.log('connected');
  12. client.subscribe("foobar/#");
  13. });
  14.  
  15. client.on("close", function () {
  16. console.log("disconnected");
  17. });
  18.  
  19. client.on("error", function (err) {
  20. console.log("error: %j", err);
  21. });
  22.  
  23. var i = 0;
  24. client.on('message', function (topic, message) {
  25. console.log("\n%s) %s : %s", i, topic, message.toString());
  26. i++;
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement