mqtt-resource
v1.0.3
Published
easily connect and handle events from an mqtt source
Downloads
1
Readme
##Why I made this package: I wanted a quick and configurable way to deal with MQTT pub/sub
##Sample JS File
const MQTTResource = require('mqtt-resource');
const messageHandler = (message) => {
try {
console.log(JSON.parse(message))
} catch (e) {
console.log(e)
}
}
const options = {
user: 'yourUsername', /* required */
apiKey: 'yourApiKeyOrPassword', /* required */
host: 'mqtts://io.adafruit.com', /* I haven't tested with any other service, please let me know if others work! */
subscribeUrl: ':user/feeds/:feed', /* same comment as above */
messageHandler: messageHandler /* optional function: if passed you'll be subscribed to the topic */
port: 8883 /* default */
}
const resource = new MQTTResource(options);
resource.on('ready', () => {
/*
this event is fired once connected to the service
only needed if you're planning on publishing
*/
resource.publish("Hello!")
});