Skip to content

Node-RED MQTT Node — Complete Guide

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Node. We cover key concepts, practical examples, and best practices.

Hook

Your Node-RED MQTT node shows a red dot (disconnected) or receives no messages even though the dot is green. The MQTT broker is running, other clients can publish and subscribe, but Node-RED's MQTT input node stays silent.

The Wrong Way

Creating multiple MQTT broker configurations for the same broker causes Node-RED to open duplicate connections, which can exceed the broker's client limit.

# BAD: Duplicate broker configs
# flow1: MQTT broker "My Broker" (192.168.1.50:1883)
# flow2: MQTT broker "My Broker 2" (192.168.1.50:1883)
Broker: 2 connections from same client ID
Connection rejected: "Client ID already connected"
Duplicate connections cause broker to disconnect both

Each MQTT broker config creates a separate connection. Reuse one config for all MQTT nodes.

The Right Way

Use a single MQTT broker configuration and verify connection details.

# 1. Check the MQTT broker node status
# Look at the small dot under the MQTT broker config node
# Red: disconnected, Green: connected
# 2. Test the connection manually
mosquitto_pub -h 192.168.1.50 -p 1883 -u user -P pass -t test -m "hello"
mosquitto_sub -h 192.168.1.50 -p 1883 -u user -P pass -t test -C 1
(messages flow correctly)

If the manual test works but Node-RED does not:

# 3. Check the broker config node
# Double-click → Edit → Verify:
# - Server: 192.168.1.50
# - Port: 1883
# - Client ID: (unique, leave blank for auto)
# - Keep alive: 60
# - Clean session: true
# 4. Enable MQTT debugging in settings.js
# In ~/.node-red/settings.js:
mqtt:
  debug: true
# 5. Restart Node-RED and watch the logs
node-red-stop && node-red-start
journalctl -u node-red -n 50 -f
[info] [mqtt-broker:My Broker] Connected to broker at 192.168.1.50:1883
[info] [mqtt-broker:My Broker] Subscribed to topic: home/#

Prevention

  • Reuse a single broker config node for all MQTT in/out nodes.
  • Use a unique client ID for Node-RED or leave it blank for auto-generation.
  • Set "Clean session: true" for development, "false" for production to receive queued messages.
  • Test with mosquitto_pub/sub before blaming Node-RED.
  • Monitor the broker's connection list to verify Node-RED is connected.

Common Mistakes with red mqtt node

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world NODE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

Why does the MQTT node show a green dot but receive no messages?

The connection is established (green dot) but the subscription topic may not match the publishing topic. Check the "Topic" field in the MQTT input node. Wildcards like # must be at the end.

What does 'Clean session' do?

When true, the broker clears all subscriptions and queued messages when the client disconnects. When false, the broker stores messages for offline clients and delivers them on reconnection.

Can I use TLS for MQTT in Node-RED?

Yes — use mqtts:// protocol in the server URL and set the port to 8883. Upload the CA certificate in the broker config node if the broker uses a self-signed certificate.


DodaTech — MQTT messages that arrive in Node-RED.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro