mqtthook

0.0.8 • Public • Published

MQTThook

It is a npm module to setup MQTThooks (MQTT version of Webhook) for IoT devices. It helps MQTT-based IoT devices interact with real-world Web applications/services easier and faster with automation services (e.g. IFTTT, Zapier, or others).

Try It

Go to the RunKit page to setup an example MQTThook and use the Websocket-based MQTT client or build a real air quality monitoring station to trigger it. Demo

The code of the MQTThook example:

var MQTThook = require('mqtthook');
var mqtthook = new MQTThook('mqtt://test.mosquitto.org');
mqtthook.hook('hooked-topic')
        .trigger(data => { console.log(`PM2.5: ${data.pm2_5} μg/m3`); });

You can send a JSON data with the format { "pm2_5": 17 } to the hooked-topic topic on the mqtt://test.mosquitto.org broker to trigger the MQTThook. The RunKit page will show the PM2.5 value you send to.

How-to

Initialize a MQTThook instance.

var MQTThook = require('mqtthook');
var mqtthook = new MQTThook('mqtt://test.mosquitto.org');

Trigger a callback function to print the PM2.5 data on the console when a hooked MQTT topic received the data.

mqtthook.hook('hooked-topic')
        .if(data => { return data.pm2_5 > 70; })
        .trigger(data => { console.log(`PM2.5: ${data.pm2_5} μg/m3`); });

Trigger a WebHook which will store the data in a Google Sheets sheet when a hooked MQTT topic received PM2.5 data.

mqtthook.hook('hooked-topic').trigger('https://webhook.fake/hooks/3345678');

Trigger a MQTThook which will forward PM2.5 data to another MQTT topic when a hooked MQTT topic received the PM2.5 data.

mqtthook.hook('hooked-topic').trigger('triggered-topic');

Reference

  • MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol.
  • Webhook in web development is a method of augmenting or altering the behavior of a web page, or web application, with custom callbacks.

Package Sidebar

Install

npm i mqtthook

Weekly Downloads

9

Version

0.0.8

License

none

Last publish

Collaborators

  • evanxd