Created
October 29, 2017 07:31
-
-
Save ardyantohermawan/b199b6c7ce5e5573835d8f6ad0391e06 to your computer and use it in GitHub Desktop.
MQTT Client using NodeJS
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
var mqtt = require('mqtt') | |
var client = mqtt.connect('mqtt://test.mosquitto.org') | |
client.on('connect', function () { | |
client.subscribe('presence') | |
client.publish('presence', 'Hello mqtt') | |
}) | |
client.on('message', function (topic, message) { | |
// message is Buffer | |
console.log(message.toString()) | |
client.end() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment