Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Created September 29, 2019 13:55
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 tuannguyenssu/558c9c060ab3027fc114c1ba1b2cbc8f to your computer and use it in GitHub Desktop.
Save tuannguyenssu/558c9c060ab3027fc114c1ba1b2cbc8f to your computer and use it in GitHub Desktop.
var mqtt = require('mqtt')
var settings = {
mqttServerUrl : "localhost",
port : 18833,
topic : "myTopic"
}
var client = mqtt.connect('mqtt://' + settings.mqttServerUrl + ":" + settings.port);
client.on('connect', function () {
client.subscribe(settings.topic)
console.log("Subscribed topic " + settings.topic);
})
client.on('message', function (topic, message) {
console.log(message.toString());
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment