Preventing MQTT Message Loops
A common misconfiguration in networks with MQTT gateways is the "MQTT loop" — packets sent over LoRa get forwarded to MQTT, which then re-injects them back into the LoRa network, causing each message to be transmitted multiple times and rapidly increasing channel utilization.
How MQTT Loops Happen
- Node A sends a message over LoRa
- Gateway node G receives the LoRa packet and publishes it to MQTT
- MQTT broker delivers the packet to Gateway G's downlink subscription
- Gateway G injects the packet back into the LoRa network
- Node A receives its own message again as if from the MQTT cloud
- This can loop indefinitely if not properly configured
Prevention: The ignore_mqtt Setting
The most important anti-loop protection is the lora.ignore_mqtt flag. When enabled, a node will not re-broadcast packets that originated from MQTT (identified by the "via MQTT" flag in the packet header):
# Enable on ALL infrastructure nodes (routers, repeaters):
meshtastic --set lora.ignore_mqtt true
# Verify:
meshtastic --get lora.ignore_mqtt
Critical: Set this on every ROUTER, ROUTER_CLIENT (deprecated; use ROUTER or REPEATER instead), and REPEATER role node in your network. Leave it as false only on end-client nodes that may need to receive messages downlinked from MQTT.
Gateway Configuration Best Practices
# Configure the gateway node correctly:
# 1. Enable MQTT publishing (uplink):
meshtastic --ch-index 0 --ch-set uplink_enabled true
# 2. Enable MQTT subscribing (downlink) ONLY if needed:
# Only enable downlink if you want to receive messages sent to MQTT
# from the global mesh or other external systems.
# If you only want to publish (monitoring), keep downlink disabled:
meshtastic --ch-index 0 --ch-set downlink_enabled false
# 3. Enable ignore_mqtt on the gateway node itself:
meshtastic --set lora.ignore_mqtt true
Detecting a Loop in Progress
Signs that a loop is occurring:
- Channel utilization (CU) rapidly increasing after enabling MQTT
- Messages appearing in the chat multiple times
- The same packet ID appearing in MQTT subscription twice or more within a few seconds
- Nodes reporting high packet counts in stats
# Check channel utilization (should be under 15% in normal operation):
meshtastic --get channel_utilization
# Monitor for duplicate packet IDs via MQTT:
mosquitto_sub -t "msh/US/2/e/#" -v | grep -E "packet.id"
# Watch for repeating IDs within 30 seconds