Adding MQTT Connection to Node-RED Flow





This guide demonstrates how to add an MQTT connection to the the Node-RED flow from the Processing DRO Data in Node-RED guide.

Prerequisites:

Mosquitto MQTT or a similar MQTT broker needs to be installed and running. For instructions on how to install Mosquitto, click here. The necessary flow nodes come preinstalled in Node-RED.

Getting Started

Take the flow from the "Processing DRO Data in Node-RED" example and drag an MQTT Out node into it, connecting it to the Join node.

A Node-RED flow with the following layout: A Seral Input node leading into 3 functions: Parse DRO Data, Add Timestamp, and Add Client ID. These functions all output to a Join Values Node which output to a debug node and the topic we're sending data across.

Configuration Steps:

1. Add the MQTT Out Node:

  • Drag the MQTT Out node into the flow and connect it to the Join node.

  • Double-click the MQTT Out node to configure it.

2. Define the Topic:

  • In the Topic field, enter the topic under which you want to publish the Axes Data from your lathe:
    Purdue/IE/Lambertus/BuildatScale/CNC/Acra/ATL-618EVS/Telemetry/Axes

  • Select QoS 1. QoS (Quality of Service) 1 ensures that the message is delivered at least once, guaranteeing that the subscriber receives the message.

    An edit MQTT Node menu with the following fields populated with the following values: Server: GatewayLabs Central Broker, Topic: Purdue/IE/Lambertus/BuildatScale/CNC/Acra/ATL-618EVS/Telemetry/Axes, QoS: 1.

3. Configure the MQTT Broker:

  • Click the + button next to the Server dropdown to add a new MQTT broker configuration.

  • Enter the IP address and port of the MQTT broker you have configured. Let it connect automatically.

  • If you have set up TLS security for your server, configure it accordingly. You can find instructions on setting up TLS here.

    An edit MQTT-broker node menu with the Name property set to GatewayLabs Central Broker. Under the Connection category the following fields are populated with the following values: Server: 192.168.4.128, Port: 8882, Connect Automatically: True, Use TLS: True and TLS configuration, Protocol: MQTT V3.1.1, Client ID: BLANK, Keep Alive: 60, Session: True.

4. Configure TLS (if applicable):

  • Upload the CA Certificate and select the server certificate.

  • If you're connected via XRDP using Chrome, you may have trouble uploading the CA certificate. To avoid this issue, connect directly to the Raspberry Pi or use Firefox while using XRDP.

    The edit tls-config node menu with the CA certificate uploaded and the Verify server certificate box checked.

5. Set User Credentials:

  • In the Security tab, enter your MQTT broker username and password.

    The edit mqtt-broker node menu in the security tab the Username and Password are filled from the broker configuration process.

6. Update and Deploy

  • Click Update and Deploy to apply the changes.

By following these steps, you will be able to add an MQTT connection to your existing Node-RED flow, allowing you to publish the parsed DRO data to an MQTT broker for further use in other applications.