Giter Site home page Giter Site logo

post2mqtt's Introduction

post2mqtt

A easy help to convert http posts to mqtt events. This is how it works.

  • The system listens to post events.
  • The url in the post is used as the mqtt-topic.
  • The bodu in the post is used as the mqtt-message

Usages

I use this in my home assistant automation. Especially for webhooks from iftt. This saves me from giving out the home assistant api token and also I get to use mqtt

Configuration variables

Environment variables:

Name Descripttion Default value
PORT The port to listen on for the http requests 8080
MQTT_URL The url to the mqtt server mqtt://localhost
MQTT_USERNAME Username for the MQTT server ''
MQTT_PASSWORD Password for the MQTT ''
MQTT_RETAIN MQTT retain flag for messages. Valid values are true, false. false
TOKEN Token that caller should use to authenticate with ''

Examples

From source

The server is started with TOKEN=theauthtoken yarn start then

curl -d '{"key1":"value1", "key2":"value2"}' \
 -H "Content-Type: application/json" \
 -H "Authorization: theauthtoken" \
 -X POST http://localhost:8080/a/b

Whould post

{ "key1": "value1", "key2": "value2" }

to the a/b mqtt topic to the localhost mqtt

If you cant use Authorization header thefollowing does the same thing

curl -d '{"key1":"value1", "key2":"value2"}' \
 -H "Content-Type: application/json" \
 -X POST http://localhost:8080/a/b?token=theauthtoken

Docker

The server can be started from docker

docker run --rm -e TOKEN=theauthtoken \
           -e MQTT_URL="mqtt://192.168.0.3" \
           -p 8080:8080 mtand/post2mqtt

post2mqtt's People

Contributors

renovate[bot] avatar renovate-bot avatar mtandersson avatar dependabot[bot] 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.