Mqtt Topic Wildcard
DodaTech
1 min read
In this tutorial, you'll learn about MQTT Wildcard Subscription Not Matching. We cover key concepts, practical examples, and best practices.
The Problem
MQTT wildcard subscription does not match expected topics.
Quick Fix
Wrong
client.subscribe('sensors/#') # Matches sensors/temp, sensors/+/temp
Subscribe matches correctly but unexpected topics are also received.
Right
// Single-level wildcard: +
client.subscribe('sensors/+/temp')
// Matches: sensors/room1/temp, sensors/room2/temp
// Does NOT match: sensors/temp, sensors/room1/humidity
// Multi-level wildcard: # (must be last)
client.subscribe('sensors/#')
// Matches: sensors/temp, sensors/room1/temp, sensors/room1/humidity
// Does NOT match: data/sensors/temp
// No wildcard — exact match only
client.subscribe('sensors/room1/temp')
// Matches: sensors/room1/temp only
Subscriptions match only topics within the expected hierarchy.
Prevention
- matches exactly one level (between slashes). # matches zero or more levels (must be last). Topics are case-sensitive (Sensor/Temp != sensor/temp). $SYS topics are reserved for broker stats. Do not publish to $SYS topics. Use + and # carefully to avoid receiving unintended messages.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro