An MQTT connection is established through the exchange of CONNECT and CONNACK packets. This exchange allows the endpoints to mutually communicate their capabilities.
async_mqtt
automatically updates the internal state of the endpoints when sending or receiving these packets.
-
client: For high-level MQTT client operations
-
The client contains an endpoint internally. The client sends and receives endpoint setting-related packets via
async_start()
. See Client APIs
-
-
endpoint: For detailed MQTT operations
-
To send and receive packets, use the async_send() and async_recv() member functions. See Send/Recv packets
-
MQTT v3.1.1
CONNECT Packet
Send (client only)
-
If
keep_alive
is set to a value greater than 0,PINGREQ
packet sending is configured. APINGREQ
packet is sent if no other packet is sent within thekeep_alive
seconds. -
If
clean_session
is set to true, the endpoint’s Session State is cleared. See keeps session.
Receive (server only)
-
If
keep_alive
is set to a value greater than 0,PINGREQ
receiving timeout is configured. If no packet is received withinkeep_alive
* 1.5 seconds after the last packet, the connection is disconnected. -
If
clean_session
is set to false, the session state storage is configured. See keeps session.
CONNACK Packet
Receive (client only)
-
If
session_present
is set to false, the endpoint’s Session State is cleared. The configured session state setting is retained, meaning that if a PUBLISH packet with QoS 1 or QoS 2 is sent, it will be stored. Ifsession_present
is set to true, stored PUBLISH and PUBREL packets are sent.
MQTT v5.0
CONNECT Packet
Send (client only)
-
If
clean_start
is set, the endpoint’s Session State is cleared. See Keep session. -
If
topic_alias_maximum
is set, prepare thetopic name
-topic alias
map for sending. See Topic Alias. -
If
receive_maximum
is set, the receive maximum for incoming packets is configured. See Receive Maximum. -
If
maximum_packet_size
is set, the maximum packet size for incoming packets is configured. See Maximum Packet Size. -
If
session_expiry_interval
is set to a value greater than 0, session state storage is configured. See Keep session.
Receive (server only)
-
If
keep_alive
is set to a value greater than 0,PINGREQ
receiving timeout is configured. If no packet is received withinkeep_alive
* 1.5 seconds after the last packet, the connection is disconnected. -
If
topic_alias_maximum
is set, prepare thetopic name
-topic alias
map for receiving. See Topic Alias. -
If
receive_maximum
is set, the receive maximum for outgoing packets is configured. See Receive Maximum. -
If
maximum_packet_size
is set, the maximum packet size for outgoing packets is configured. See Maximum Packet Size. -
If
session_expiry_interval
is set to a value greater than 0, session state storage is configured. See Keep session.
CONNACK Packet
Send (server only)
-
If
topic_alias_maximum
is set, prepare thetopic name
-topic alias
map for sending. See Topic Alias. -
If
receive_maximum
is set, the receive maximum for incoming packets is configured. See Receive Maximum. -
If
maximum_packet_size
is set, the maximum packet size for incoming packets is configured. See Maximum Packet Size. -
If
session_expiry_interval
is set to a value greater than 0, session state storage is configured. See Keep session.
Receive (client only)
-
If
session_present
is set to false, the endpoint’s Session State is cleared. The configured session state setting is retained, meaning that if a PUBLISH packet with QoS 1 or QoS 2 is sent, it will be stored. Ifsession_present
is set to true, stored PUBLISH and PUBREL packets are sent. -
If
topic_alias_maximum
is set, prepare thetopic name
-topic alias
map for receiving. See Topic Alias. -
If
receive_maximum
is set, the receive maximum for outgoing packets is configured. See Receive Maximum. -
If
maximum_packet_size
is set, the maximum packet size for outgoing packets is configured. See Maximum Packet Size. -
If
server_keep_alive
is set,PINGREQ
packet sending is overridden. APINGREQ
packet is sent if no other packet is sent within theserver_keep_alive
seconds.