Mosquitto: Understanding MQTT Topics

This documentation is part of the Getting Started guide. You can view the complete guide here: How to Get Started with Mosquitto.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Mosquitto MQTT cloud solution that provides a host of benefits, including:

  • Unlimited message exchanges and transfers.
  • Unlimited device authentication via an external API.
  • Advanced ACLs on topics, users, and actions.
  • Customizable domain name secured with HTTPS (for example, https://mqtt.your-company.com).
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Mosquitto MQTT cloud hosting solution!

MQTT organizes communication into "topics", which act as channels for publishing and subscribing to data. Devices publish messages to specific topics or subscribe to them to receive relevant updates.

Topics in MQTT are case-sensitive, must contain UTF-8 characters, and require at least one character. The hierarchy within topics is defined using the slash (/) character.

Here is an example setup for IoT devices collecting temperature and humidity data, identified by their MAC addresses:

  • For a device with MAC address 00:00:00:00:00:00:

    • Temperature: devices/00:00:00:00:00:00/temperature
    • Humidity: devices/00:00:00:00:00:00/humidity
  • For a device with MAC address 11:11:11:11:11:11:

    • Temperature: devices/11:11:11:11:11:11/temperature
    • Humidity: devices/11:11:11:11:11:11/humidity

Applications can subscribe to a specific topic, such as devices/00:00:00:00:00:00/temperature, to receive data from the respective IoT device.

MQTT supports wildcards for efficient topic management:

  • The + wildcard matches a single level in the topic hierarchy. For example, subscribing to devices/+/temperature captures topics like devices/1/temperature but not devices/1/2/temperature.

  • The # wildcard matches multiple levels. For instance, devices/# matches topics such as devices/1/temperature, devices/2/humidity, and devices/1/2/somethingElse.