Adding an MQTT broker
You need to add an MQTT broker to subscribe or publish to MQTT topics.
- Open Node-RED.
- Add an mqtt node from the input category or the output category to the workspace.
- Double-click the mqtt node to open the Edit node dialogue.
- In the drop-down list Server, select Add a new mqtt-broker....
- Click the Pen icon to open the Add new mqtt-broker config node dialogue.
- In the text box Name, enter a name for the node.
- Select the Connection tab.
- In the text box Server, enter the adress of the MQTT broker.
- In the text box Port, enter the port you want to use.
NOTICE

We recommend enabling transport layer security (TLS), especially if you are using a username and a password to authenticate to an MQTT broker.
- Enable the check box Enable secure (SSL/TLS) connection
- In the drop-down list TLS Configuration, select a TLS configuration to use or add a new TLS configuration.
- In the text box Client ID, enter a client ID unique to the broker or leave it blank for autogenerating a client ID.
- In the text box Keep alive time (s), enter the time you want the broker to keep the TCP connection open without receiving a package.
NOTICE

Setting the keep alive time to zero, disables the keep alive function.
- If you want to use clean sessions everytime the connection is established, enable the check box Use clean session.
NOTICE

Use clean sessions if you are using the MQTT broker only for publishing or if it does not matter, that the client misses messages while being offline.
- If you want to enable MQTT 3.1 support, enable the check box Use legacy MQTT 3.1 support.
- Select the Security tab.
- In the corresponding text boxes, enter the username and password for authenticating to the MQTT broker.
- Select the Messages tab.
NOTICE

MQTT offers ways to inform all participants about the network status of a particular client.
- Birth message: sent by the client, when the connection is established
- Close message: sent by the client, before the connection is closed
- Will message: sent by the broker, when the client is disconnected unexpectedly
- In the text boxes Topic, enter the topic to which the respective message shall be published.
- In the text boxes Payload, enter the payload of the respective message.
- In the drop-down lists Retain, select whether the respective message shall be retained on the broker.
- In the drop-down lists QoS, select the Quality of Service level of the respective message. Choose from:
- 0 (fire and forget): Arrival of the message solely relies on the underlying Internet Protocol network. Message loss may occur.
- 1 (at least once): The message is assured to arrive, but may arrive more than once.
- 2 (once and once only): The message is assured to arrive once and only once.
- Click Done to apply your changes.
- An MQTT config node is added. This node establishes a single connection to the broker, which can be used by MQTT nodes to publish or subscribe to topics on that broker.