Mosquitto: Understanding MQTT Topics

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

👋 Welcome to the Stackhero documentation!

Stackhero provides you with a fully managed Mosquitto MQTT cloud environment, designed for reliability and flexibility:

  • Unlimited message throughput and data transfers, so your workflows never encounter artificial limits.
  • Unlimited device authentication via your own external API, making onboarding and access management straightforward.
  • Advanced ACLs for precise control over topics, users, and actions.
  • A custom domain name with integrated HTTPS for secure, branded endpoints (for example: https://mqtt.your-company.com).
  • Effortless updates: apply improvements or security patches with a single click.
  • Consistent performance and enhanced security, with every instance running on a private, dedicated infrastructure.

Accelerate your IoT projects and reduce operational overhead. You can have a secure, production-ready Mosquitto MQTT cloud hosting instance up and running in just a few minutes.

MQTT organises 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.