Code Monkey home page Code Monkey logo

mqtthook's Introduction

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.

mqtthook's People

Contributors

evanxd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fliiteai

mqtthook's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.