Created
April 16, 2021 12:36
-
-
Save suru-dissanaike/51fd7c0f2f17029c97f74f4b429a814a to your computer and use it in GitHub Desktop.
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
const mqtt = require('async-mqtt'); | |
const MTPMQTTTopic = '/himinds/'; | |
const HOST = "wss://test.mosquitto.org:8081"; // <-- change to your host and port 443 | |
const optionsLocal = { | |
username: 'himinds', | |
password: 'TcV1YrduetnMmxx9' | |
}; | |
(async () => { | |
const client = await mqtt.connectAsync(HOST,optionsLocal).catch(error => console.log(error)); | |
if (client === undefined) | |
process.exit(); | |
await client.subscribe(MTPMQTTTopic).catch(error => console.log(error)); | |
await client.publish(MTPMQTTTopic,"Hello HiMinds").catch(error => console.log(error)); | |
client.on('message', function (topic, message) { | |
console.log("topic: " + topic); | |
console.log(message.toString()); | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment