3 Engineering IoT Networks
151
Subscriber
Broker
Publisher
CONNECT
CONNACK
19
PUBLISH
(Topic:"temperature/home")
19 °C
SUBSCRIBE
(Topic:"temperature/home")
DISCONNECT
Fig. 3.29 Example of MQTT protocol operation at QoS Level 0
10. UNSUBSCRIBE: An UNSUBSCRIBE Packet is sent by the Client to the Server
to unsubscribe from topics.
11. UNSUBACK: The UNSUBACK Packet is sent by the Server to the Client to
confirm receipt of an UNSUBSCRIBE Packet.
12. PINGREQ: The PINGREQ Packet is sent from a Client to the Server. It can be
used to:
• Indicate to the Server that the Client is alive in the absence of any other
Control Packets being sent from the Client to the Server.
• Request that the Server responds to confirm that it is alive.
• Exercise the network to indicate that the Network Connection is active.
13. PINGRESP: The Server sends a PINGRESP Packet to the Client in response to
a PINGREQ Packet. It indicates that the Server is alive.
14. DISCONNECT: The DISCONNECT Packet is the final Control Packet sent from
the Client to the Server. It indicates that the Client is disconnecting cleanly.
MQTT supports three Quality of Service (QoS) levels, which determine the
protocol’s behavior and how it manages the communication. The first QoS level is
shown in Fig. 3.29 and is referred to as at most once, or fire and forget. The publisher
sends a message to the broker one time and then deletes the sent data. The broker
receives the data and sends it to the subscribers one time. The second QoS level is
shown in Fig. 3.30 and is referred to as at least once. In this case, each publish action
from the publisher and the broker, and from the broker to the subscriber, is followed
by an acknowledge. If an acknowledge is not received promptly, the packet is sent
again. The third QoS level is shown in Fig. 3.31 and is referred to as exactly once.
In this third scenario, the mechanism requires two pairs of messages to be sent. The
first pair is publish/pubrec, and the second is pubrel/pubcomp. These two pairs of
messages ensure that, even with multiple retries, subscribers receive the data only
one time.
One of the benefits of the MQTT protocol is that it preserves battery power and
efficiently delivers messages. There are other Application Layer protocols with a
similar publish/subscribe paradigm, e.g., the Advanced Message Queuing Protocol
Précédent

- 159/647

Suivant