Publishing messages to an MQTT topic

  1. Open Node-RED.
  2. Add an mqtt node from the output category to the workspace.
  3. Connect the input of the mqtt node to the output of the node whose output you want to publish.
  4. Double-click the mqtt node to open the Edit node dialogue.
  5. In the Server drop-down list, select a server to connect to or add a new MQTT broker.
  6. notice

    You can set topic, QoS and retain dynamically via message properties by leaving the corresponding fields blank.

  7. In the Topic text box, enter the topic you want the node to publish to.
  8. In the QoS drop-down lists, select the Quality of Service level of the respective message. Choose from:
  9. 0 (fire and forget): Arrival of the message solely relies on the underlying Internet Protocol network. Message loss may occur.
  10. 1 (at least once): The message is assured to arrive, but may arrive more than once.
  11. In the Retain drop-down list, select whether messages shall be retained on the broker.
  12. Click Done to apply your changes.

Adding an MQTT broker