0

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
    }
    
  2. 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.

  • Answered questions are not being migrated and should not be cross-posted. Since this has been solved please do not post again on SO. – Helmar Jan 20 at 12:50
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.

  • Yes, i've attempted this. but what i require is the persistent connection mqtt has so that it will automatically receive/fetch data whenever there is new data input. Using http-get, i'll have to use inject to force it to get data (even where there is no new data). – Eric Lim Jan 9 at 9:39
  • No it won't, the HTTP-in node listens for connections, there is nowhere to put an inject node in what I've described – hardillb Jan 9 at 9:41
  • does this mean that there is a way to get the HTTP-in in Node-RED to listen for new POST requests and fetch data only if there is new data available? – Eric Lim Jan 9 at 10:05
  • The HTTP-in node listens for request made to it and passes on the data, there is nothing to pass on until there is a request made. Read the info sidebar doc – hardillb Jan 9 at 10:22
  • Okay! I'll head home tonight, try it out and get back here. Thank you! – Eric Lim Jan 9 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.