Subscribing to an MQTT topic
Code snippet for subscribing to an MQTT topic
by spotto
JavaScript
const main = async () => {
// Use code snippet from connecting to MQTT section
const client = connect();
const topic = 'OrgnisationID/Arrived/AssetID';
client.subscribe(topic);
client.on('message', (topic, message) => {
// message is in Buffer format
console.log(message.toString())
// Run your bespoke logic here
});
};
main();