Convert http request to mqtt message

This flow listens for http (/mqtt) requests, extracts topics and messages, and sends the extracted message to the extracted mqtt topic.

This way you can send mqtt messages via http.

Flow flow

One of my own use cases is sending mqtt messages from my Flic hub, which natively supports sending http requests, but not mqtt messages.


Copy the flow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option.

[{"id":"12b452fa.fb4d2d","type":"tab","label":"HTTP to MQTT","disabled":false,"info":""},{"id":"97ff10ce.a42db","type":"http in","z":"12b452fa.fb4d2d","name":"[get] /mqtt","url":"/mqtt","method":"get","upload":false,"swaggerDoc":"","x":100,"y":120,"wires":[["b618744.7db6b88","fdaf0628.3b4d38"]]},{"id":"2115ae8f.653152","type":"mqtt out","z":"12b452fa.fb4d2d","name":"send extracted mqtt message","topic":"","qos":"2","retain":"false","broker":"","x":640,"y":160,"wires":[]},{"id":"96fbe86a.0b7f88","type":"inject","z":"12b452fa.fb4d2d","name":"Send http request","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":260,"wires":[["3c5eb653.f89e6a"]]},{"id":"3c5eb653.f89e6a","type":"http request","z":"12b452fa.fb4d2d","name":"http://192.168.3.62:1880/mqtt?topic=test_topic&message=test_message","method":"GET","ret":"txt","paytoqs":false,"url":"http://192.168.3.62:1880/mqtt?topic=test_topic&message=test_message","tls":"","persist":false,"proxy":"","authType":"","x":510,"y":260,"wires":[["34c899e9.235996"]]},{"id":"b618744.7db6b88","type":"change","z":"12b452fa.fb4d2d","name":"extract topic and message","rules":[{"t":"move","p":"payload.topic","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"payload.message","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":160,"wires":[["2115ae8f.653152"]]},{"id":"fdaf0628.3b4d38","type":"http response","z":"12b452fa.fb4d2d","name":"give standard http response","statusCode":"","headers":{},"x":360,"y":120,"wires":[]},{"id":"b651bd52.a22ce","type":"http in","z":"12b452fa.fb4d2d","name":"[post] /mqtt","url":"/mqtt","method":"post","upload":false,"swaggerDoc":"","x":110,"y":160,"wires":[["b618744.7db6b88","fdaf0628.3b4d38"]]},{"id":"3af1d7c1.fc21c8","type":"mqtt in","z":"12b452fa.fb4d2d","name":"","topic":"test_topic","qos":"2","datatype":"auto","broker":"","x":100,"y":320,"wires":[["34c899e9.235996"]]},{"id":"34c899e9.235996","type":"debug","z":"12b452fa.fb4d2d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":320,"y":320,"wires":[]},{"id":"fb4fcfda.e6a61","type":"comment","z":"12b452fa.fb4d2d","name":"Test this flow using your own Node-RED IP address","info":"","x":230,"y":220,"wires":[]},{"id":"108aa35c.e04c8d","type":"comment","z":"12b452fa.fb4d2d","name":"Convert http request to mqtt message","info":"","x":190,"y":70,"wires":[]},{"id":"f0949145.6bfde","type":"comment","z":"12b452fa.fb4d2d","name":"link to latest version of this and my other flows: https://flows.nodered.org/collection/YsSoz9IDM4Z_","info":"","x":380,"y":30,"wires":[]}]

Flow Info

Created 5 years, 4 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • change (x1)
  • comment (x3)
  • debug (x1)
  • http in (x2)
  • http request (x1)
  • http response (x1)
  • inject (x1)
  • mqtt in (x1)
  • mqtt out (x1)
Other
  • tab (x1)

Tags

  • mqtt
  • http
  • flic
  • flichub
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option