3

Not sure how much better I can phrase it in the question but i'll try to explain to the best I can.

What I am trying to do:

  1. Using IFTTT Webhook to POST a JSON message in MQTT Format.

    POST URL: test.mosquitto.org
    E.G:

   {
       "payload:": "kitchen",
       "topic:": "device/state",
       "retain:": true,
       "qos": 2
   }
  1. Using a Node-RED mqtt input (subscribe) node with the settings configured to test.mosquitto.org port 1883 and topic set to device/state, I should be able to retrieve the payload I've published to the mosquitto broker to my Node-RED node.

What went wrong
I think something might be wrong with the POST to the test.mosquitto.org broker.

Troubleshooting
By using mosquitto_pub and mosuqitto_sub commands, I'm able to to receive the payload in my Node-RED (which means that my Node-RED mqtt node is configured correctly).

Commands:
Terminal 1: mosquitto_sub -h test.mosquitto.org -t device/state -d
Terminal 2: mosquitto_pub -h test.mosquitto.org -t device/state -m "kitchen"

Node-RED successfully receives the message in JSON object format. But it doesn't receive anything when I attempt to publish through Postman using POST method to the URL.

Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90
Eric Lim
  • 161
  • 1
  • 8

1 Answers1

3

MQTT brokers are not HTTP servers, you can not POST to broker, it just won't work.

MQTT and HTTP are two totally different protocols, if you want to bridge them you will need to write program to do that. Doing so in Node-RED is trivial.

HTTP-in set to receive POSTs --> MQTT-out to publish to broker
                             |
                             --> HTTP-response node (to close out the HTTP session)

You can set the topic to publish to in the HTTP-in node, or insert a function node between HTTP-in node and the MQTT-out node to set topic and qos settings if you need to.

hardillb
  • 12,813
  • 1
  • 21
  • 34