This is a MQTT Agent
It is a simplification of MQTT in NodeJS. All functions return a native-promise that you can use Asynchronously.
Installation
$ npm install --save mqtt-agent
Usage
const mqttAgent = require('mqtt-agent');
const agent = new MQTTAgent('mqtt://your-mqtt-server:8883', (topic, msg) => {
});
agent.connect()
.then((connected) => {
console.log('Connected:', connected);
return agent.subscribe('your_topic/your_device/something');
})
.then((subscribedTopic) => {
console.log('Topic subscribed to:', subscribedTopic);
return agent.publish('yourTopic', 'yourMessage can be a JS Object or string');
})
.then((published) => {
console.log('Published (boolean):', published);
return agent.end();
})
.then((disconnected) => {
console.log('Disconnected:', disconnected);
})
.catch((error) => {
console.log('Error:', error);
});
License
© Javier Cañadilla