MQTT topics are used to categorize, or group, messages together in a hierarchical format. We have already been working with topics in our proceeding command-line examples, but in a non-hierarchical fashion. Wildcards, on the other hand, are special characters used by a subscriber to create flexible topic matching patterns.
Here are a few hierarchical topic examples from a hypothetical building with sensors. The hierarchy is delimited by the / character:
- level1/lounge/temperature/sensor1
- level1/lounge/temperature/sensor2
- level1/lounge/lighting/sensor1
- level2/bedroom1/temperature/sensor1
- level2/bedroom1/lighting/sensor1
There is no need to pre-create a topic on an MQTT broker. Using the default broker configuration (which we are), you just publish and subscribe to topics at will.
When the Mosquitto broker is configured to use authentication, there is the possibility to restrict access to topics based on a client ID and/or username...