Created
August 2, 2021 21:25
-
-
Save sjg/bca2ae4083dea3f2a20fe44e2d901d57 to your computer and use it in GitHub Desktop.
A Simple Node Client to connect to a MQTT Broker
This file contains hidden or 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
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