Skip to content

Instantly share code, notes, and snippets.

@cbh6
Created April 27, 2018 10:57
Show Gist options
  • Save cbh6/0bc0d1febc76c0ed0c3d6cccd624db0d to your computer and use it in GitHub Desktop.
Save cbh6/0bc0d1febc76c0ed0c3d6cccd624db0d to your computer and use it in GitHub Desktop.
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