Coder Social home page Coder Social logo

mqtt2http's Introduction

MQTT 2 HTTP

Forward MQTT messages to HTTP.

Deploy

This simple, but highly configurable script subscribes to one or more MQTT topics and makes a HTTP request for every message it receives. This allows you to use MQTT messages as trigger for APIs that don't support MQTT via services like Zapier's Webhook or IFTTT's Maker Channel.

Deploy

Deploy directly to Heroku or clone the repository and run it in any current Node.js environment:

  • Yarn: yarn && yarn run start
  • NPM: npm install && npm start

Test

To test you can use a public MQTT broker like mqtt://test.mosquitto.org and the DEBUG_* variables. Rename debug.env to .env for an example that publishes a JSON stringified object with the current time every 5 seconds and skips the actual request.

Environment Variables

Configure the MQTT connection and topic to subscribe to and the HTTP requests to make via environment variables. The script uses dotenv to load these from a file if you like. Be aware that some of the variables can or must be formatted as JSON strings.

The following variables can be set:

Variable Required Description
MQTT_URL Yes MQTT broker URL to connect to. See https://www.npmjs.com/package/mqtt#connect
MQTT_USERNAME No MQTT broker username. See https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
MQTT_PASSWORD No MQTT broker password. See https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
MQTT_CONNECT No MQTT broker connection options. Formatted as JSON String. See https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
MQTT_TOPIC Yes MQTT topic(s) to subscribe. Either a single topic or an Array or Object formatted as JSON String. See https://www.npmjs.com/package/mqtt#subscribe
MQTT_SUBSCRIBE No MQTT subscribe options. Formatted as JSON String. See https://www.npmjs.com/package/mqtt#subscribe
HTTP_URL Yes HTTP request URL. Compiled as Handlebars template and executed with the topic and message as data. See https://www.npmjs.com/package/request#requestoptions-callback and http://handlebarsjs.com/
HTTP_JSON No Set to a truthy string (e.g. 1) to set the request option json to true and body to an object with the topic and message (as object, if available). See https://www.npmjs.com/package/request#requestoptions-callback
HTTP_REQUEST No HTTP request options. Compiled as Handlebars template and executed with the topic and message as data. Use the stringify helper if needed to output a JSON String. See https://www.npmjs.com/package/request#requestoptions-callback
DEBUG_LOG No Set to a truthy string (e.g. 1) to write debug logs to the console.
DEBUG_PUBLISH No Set to a integer string (e.g. 5000) to publish dummy topics to the broker at this interval.
DEBUG_MESSAGE No Message to publish. Defaults to a JSON formatted object with time set to Date.toString().
DEBUG_NOOP No Set to a truthy string (e.g. 1) to not actually make the HTTP request.

mqtt2http's People

Contributors

fokkezb avatar maxbaines avatar

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.