MQTT Features

Topic

In MQTT, a topic enables the filtering of messages. A hierarchical structure separated by slashes (/) is used.

Examples:

  • home/living_room/temperature → Living room temperature data.
  • vehicles/car/speed → Vehicle speed data.

Quality of Service (QoS)

In MQTT, the QoS level determines the reliability of message delivery.

  • QoS 0 (At Most Once): Messages are sent without waiting for acknowledgment. This can be used if data loss is tolerable.
  • QoS 1 (At Least Once): Messages are delivered at least once but may be repeated.
  • QoS 2 (Exactly Once): This is the most reliable level; the message is delivered only once.

Retain

The Retain feature ensures that messages are stored on the broker and forwarded to newly connected clients.

Example: If a temperature value is sent with Retain, all clients newly connecting to this topic can see that value.

To clear a Retain message, an empty message with `retain true` must be sent.