MQTT Features

Topic

In MQTT, topic allows filtering of messages. A hierarchical structure separated by a slash (/) is used.

Examples:

  • home/living_room/temperature → Temperature data for the living room.
  • vehicles/car/speed → Vehicle speed data.

Quality of Service (QoS)

The QoS level in MQTT determines the reliability of message delivery.

  1. QoS 0 (At Most Once) → The message is sent without waiting for confirmation. Available if data loss can be tolerated.
Only available if the transmitter and receiver are connected by cable.
  1. QoS 1 (At Least Once) → Message is transmitted at least once but can be repeated.
  2. QoS 2 (Exactly Once)Most reliable level, the message is delivered only once.

Retain

The Retain feature allows messages to be saved and forwarded to newly connected clients.

  • Example: If a temperature value was sent with retain, all newly connected clients can see this value.
  • To clear a retain message: Retain true should send an empty message.