Created
September 3, 2019 00:25
-
-
Save bryanbarnard/76650688858cfc5a819d20430eedb4f5 to your computer and use it in GitHub Desktop.
sample connect to sniot mqtt
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
//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