Skip to content

Instantly share code, notes, and snippets.

@ardyantohermawan
Created October 29, 2017 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardyantohermawan/b199b6c7ce5e5573835d8f6ad0391e06 to your computer and use it in GitHub Desktop.
Save ardyantohermawan/b199b6c7ce5e5573835d8f6ad0391e06 to your computer and use it in GitHub Desktop.
MQTT Client using NodeJS
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