Skip to content

Instantly share code, notes, and snippets.

@evanxd
Last active March 22, 2017 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanxd/50273f74163c085d7093eab0b7aed2a0 to your computer and use it in GitHub Desktop.
Save evanxd/50273f74163c085d7093eab0b7aed2a0 to your computer and use it in GitHub Desktop.
MQTThook

MQTThook

It is a MQTT version of Webhook for IoT devices. It helps MQTT-based IoT devices use automation services (e.g. IFTTT or Zapier) to interact with existed Web applications/services and enrich its capability.

Sample Code

Initialize a MQTThook instance.

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

Trigger a WebHook which will do some automation things when a hooked MQTT topic received real-time PM2.5 data.

mqtthook.hook('hooked-topic').trigger('https://webhooks.evanxd.io/hooks/3345678', { pm2_5: 'pm2_5' });

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

mqtthook.hook('hooked-topic').trigger((data) => { console.log(`PM2.5: ${data.pm2_5}`); });

Reference

  • MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment