MQTT Communication with Node-RED

Last updated:

Introduction

MQTT is a lightweight publish/subscribe messaging protocol widely used in Internet of Things (IoT) applications. Instead of communicating directly with each other, devices send messages to an MQTT broker under a topic, and other clients can subscribe to that topic to receive the messages.

Node-RED provides built-in MQTT nodes, making it easy to receive and process IoT messages without writing a full MQTT application. In this tutorial, we will configure Node-RED on a reComputer RK Series device to subscribe to a topic on the HiveMQ public MQTT broker, then publish a JSON message from the RK terminal to verify the connection.

Security: This example uses the shared HiveMQ public broker on TCP port 1883 without TLS or authentication. Use test data only. Do not transmit passwords, personal information, or production/industrial data. For production deployments, use an authenticated broker with TLS.

Prerequisites

ItemRequirement
HardwarereComputer RK Series device
Operating systemDebian-based ARM64 Linux
Node-REDInstalled and running; complete Getting Started with Node-RED first
NetworkInternet access to the HiveMQ public MQTT broker
AccessA web browser for Node-RED and a terminal or SSH connection to the RK device

How It Works

text
reComputer RK Terminal
(mosquitto_pub)
       |
       | Publish JSON to topic: rk3588/seeed/demo
       v
HiveMQ Public MQTT Broker
(broker.hivemq.com:1883)
       |
       | Subscribe to the same topic
       v
Node-RED on reComputer RK
MQTT in  -->  Debug
       |
       v
Debug sidebar: received JSON object

Step 1: Open the Node-RED Editor

Ensure Node-RED is running on the RK device:

bash
sudo systemctl status nodered.service --no-pager

If needed, start the service:

bash
node-red-start

If this command follows the service logs, press Ctrl+C to return to the terminal; Node-RED keeps running in the background.

Find the device's local IP address:

bash
hostname -I

From a computer on the same network, open the Node-RED editor:

text
http://<RK_DEVICE_IP>:1880

Replace <RK_DEVICE_IP> with the actual IP address of the device. Log in if editor authentication was enabled during Node-RED setup.

Step 2: Add an MQTT Input Node

  1. Open Flow 1 (or create a new flow).
  2. Search the left palette for mqtt in, then drag the purple mqtt in node onto the workspace.
  3. Double-click the node to open Edit mqtt in node.
  4. Next to Server, click the add/edit button (+ or a pencil icon, depending on the version) to create an MQTT broker configuration.

Step 3: Configure the HiveMQ Broker

In the MQTT broker configuration dialog, enter:

SettingValue
NameHiveMQ (optional display name)
Serverbroker.hivemq.com
Port1883
ProtocolMQTT V3.1.1
Client IDLeave blank to use an automatically generated ID
TLSDisabled
Username / PasswordLeave blank

HiveMQ broker connection settings

Keep the remaining options at their defaults, then click Add or Update (depending on the editor version) to save the broker configuration.

The public broker is shared by other users. Choose a topic that is unlikely to collide with other tests. This example uses rk3588/seeed/demo. If you choose a different topic, use it consistently in both the subscription and publishing command.

Step 4: Configure the MQTT Subscription

Back in Edit mqtt in node, set:

SettingValue
ServerHiveMQ
ActionSubscribe to single topic
Topicrk3588/seeed/demo
QoS0
Outputauto-detect (parsed JSON object, string or buffer)
NameSeeedStudio

MQTT input topic, QoS and output format

Click Done to save the node.

MQTT topics are case-sensitive. The topic in Node-RED must match the topic used by the command-line publisher exactly. If you change the topic to a unique value, update the publishing commands in Step 7 as well.

Step 5: Connect MQTT In to Debug and Deploy

  1. Search the palette for debug, then drag the green debug node into the workspace.
  2. Connect the output of SeeedStudio (mqtt in) to the input of the debug node.
  3. Open the Debug node settings and leave its output set to msg.payload.
  4. Click Done, then click Deploy in the upper-right corner.
  5. Open the Debug messages sidebar.

The resulting flow should look like this:

text
[SeeedStudio (mqtt in)] ----> [debug node]

Once the MQTT connection is established, the MQTT in node should show a green connected status beneath it.

Step 6: Install the MQTT Command-Line Client

In the reComputer RK device's terminal, install the Mosquitto command-line tools:

bash
sudo apt update
sudo apt install -y mosquitto-clients

The mosquitto_pub command sends an MQTT message to the broker. Node-RED, already subscribed to the same topic, can receive it.

Step 7: Publish a Test JSON Message

Run the following command in the RK terminal:

bash
mosquitto_pub \
  -h broker.hivemq.com \
  -p 1883 \
  -t "rk3588/seeed/demo" \
  -m '{"device":"RK3588","temperature":25.6}'

This command publishes one JSON message to the topic rk3588/seeed/demo using the public HiveMQ broker.

For more detailed command-line output, you can use the -d flag:

bash
mosquitto_pub -d \
  -h broker.hivemq.com \
  -p 1883 \
  -t "rk3588/seeed/demo" \
  -m '{"device":"RK3588","temperature":25.6}'

Step 8: Verify the Received Message in Node-RED

Return to the Node-RED editor and check the Debug messages sidebar. The MQTT input node should forward the message to the Debug node.

The message should contain the following data:

json
{
  "device": "RK3588",
  "temperature": 25.6
}

Because the MQTT input node's Output is configured to auto-detect JSON, Node-RED can display the payload as a parsed JavaScript object. The sidebar also identifies the topic as rk3588/seeed/demo.

Connected MQTT flow and received JSON in Debug messages

The successful message confirms this communication path:

reComputer RK terminal → HiveMQ public broker → Node-RED MQTT in → Debug

Conclusion

You have configured Node-RED on a reComputer RK Series device to connect to an MQTT broker, subscribe to a topic, and receive a JSON message published from the device's terminal. This provides a simple foundation for developing MQTT-based IoT applications on the RK platform.

In later tutorials, the MQTT flow can be extended to process sensor data, publish messages with an mqtt out node, or integrate with other industrial protocols and dashboards.

References