Sign inSign up

mtand/post2mqtt

By mtand

Updated 2 days ago

Makes mqtt events from http posts

Image
2

10K+

mtand/post2mqtt repository overview

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:

NameDescripttionDefault value
PORTThe port to listen on for the http requests8080
MQTT_URLThe url to the mqtt servermqtt://localhost
MQTT_USERNAMEUsername for the MQTT server''
MQTT_PASSWORDPassword for the MQTT''
MQTT_RETAINMQTT retain flag for messages. Valid values are true, false.false
TOKENToken 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

Tag summary

Content type

Image

Digest

sha256:94576e1d5

Size

58.4 MB

Last updated

2 days ago

docker pull mtand/post2mqtt