Skip to content

Instantly share code, notes, and snippets.

@sjg
Created August 2, 2021 21: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 sjg/bca2ae4083dea3f2a20fe44e2d901d57 to your computer and use it in GitHub Desktop.
Save sjg/bca2ae4083dea3f2a20fe44e2d901d57 to your computer and use it in GitHub Desktop.
A Simple Node Client to connect to a MQTT Broker
var mqtt = require('mqtt');
var request = require('request');
var client = mqtt.connect('mqtt://test.mosquitto.org')
client.on('connect', function () {
console.log("");
console.log("Connected to MQTT Server");
client.subscribe('#')
})
client.on('message', function (topic, message) {
// message is Buffer
console.log("TOPIC: " + topic + "\t" + message.toString())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment