Skip to content

Instantly share code, notes, and snippets.

@bryanbarnard
Created September 3, 2019 00:25
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 bryanbarnard/76650688858cfc5a819d20430eedb4f5 to your computer and use it in GitHub Desktop.
Save bryanbarnard/76650688858cfc5a819d20430eedb4f5 to your computer and use it in GitHub Desktop.
sample connect to sniot mqtt
//index.js
var pwd = 'replace with password'
var opt = {username: "subscribe",port: 8883 ,password: pwd, rejectUnauthorized: false}
var mqtt = require('mqtt')
var client = mqtt.connect('mqtts://broker.iotdemo2-dev.sniot.net', opt)
client.on('connect', function () {
client.subscribe('sniothub/rules/message', function (err) {
if (!err) {
console.log("successfully connected")
}
})
})
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