Skip to content

Instantly share code, notes, and snippets.

@suru-dissanaike
Created April 16, 2021 12:36
Show Gist options
  • Save suru-dissanaike/51fd7c0f2f17029c97f74f4b429a814a to your computer and use it in GitHub Desktop.
Save suru-dissanaike/51fd7c0f2f17029c97f74f4b429a814a to your computer and use it in GitHub Desktop.
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