[5] MQTT, mosquitto, Eclipse Paho --- MQTT Message format analysis overview, mqttpaho --- mqtt
We know that MQTT is a specification of the IOT protocol. The latest two versions of MQTT are: 3.1.1 and 3.1.0.
(1) The specification of 3.1.0 is as follows:
Http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
(2) 3.1.1 specifications are as follows:
Http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/ OS /mqtt-v3.1.1-os.html#_Toc398718029
There are still many differences between the specification 3.1.0 and 3.1.1. For example, in the variable header, In the 3.1.0 specification, the keyword is "MQISdP"
Table 1. The first eight bytes of the MQTT V3.1 standard Variable Message Header
|
Description |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Protocol Name |
Byte 1 |
Length MSB (0) |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
Byte 2 |
Length LSB (6) |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
Byte 3 |
'M' |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
Byte 4 |
'Q' |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
Byte 5 |
'I' |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
1 |
Byte 6 |
'S' |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
Byte 7 |
'D' |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
0 |
Byte 8 |
'P' |
0 |
1 |
1 |
1 |
0 |
0 |
0 |
0 |
In MQTT V3.1.1, the keyword of the protocol name in the header of the variable message is "MQTT", as shown in the figure below.
Table 2. The first six bytes of the MQTT V3.1.1 Variable Message Header
|
Description |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Protocol name |
Byte 1 |
Length MSB (0) |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
Byte 2 |
Length LSB (4) |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
Byte 3 |
'M' |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
Byte 4 |
'Q' |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
Byte 5 |
'T' |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
Byte 6 |
'T' |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
Protocol Level |
|
Description |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Byte 7 |
Level (4) |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
The specifications mainly describe the specifications and rules of common message formats, message commands, message flows, and so on. In the previous four chapters, we have a rough understanding of MQTT. In the next series of articles, I will show you the following 14 command messages of MQTT through WireShark) in addition, we will repeat it with specific specifications. Note that the java library of the Eclipse Paho API that I use supports MQTT 3.1.1 and mosquitto also supports version 3.1.1, therefore, all Packet Capturing rules in this series are based on MQTT 3.1.1, rather than MQTT 3.1. The following table describes different message types in MQTT 14.
Table 3. 14 message types of MQTT (Command message)
Name |
Value |
Information Flow Direction |
Description |
Reserved |
0 |
Forbidden |
Reserved |
CONNECT |
1 |
Client to Server |
Client request to connect to Server |
CONNACK |
2 |
Server to Client |
Connect acknowledgment |
PUBLISH |
3 |
Client to Server Or Server to Client |
Publish message |
PUBACK |
4 |
Client to Server Or Server to Client |
Publish acknowledgment |
PUBREC |
5 |
Client to Server Or Server to Client |
Publish received (assured delivery part 1) |
PUBREL |
6 |
Client to Server Or Server to Client |
Publish release (assured delivery part 2) |
PUBCOMP |
7 |
Client to Server Or Server to Client |
Publish complete (assured delivery part 3) |
SUBSCRIBE |
8 |
Client to Server |
Client subscribe request |
SUBACK |
9 |
Server to Client |
Subscribe acknowledgment |
UNSUBSCRIBE |
10 |
Client to Server |
Unsubscribe request |
UNSUBACK |
11 |
Server to Client |
Unsubscribe acknowledgment |
PINGREQ |
12 |
Client to Server |
PING request |
PINGRESP |
13 |
Server to Client |
PING response |
DISCONNECT |
14 |
Client to Server |
Client is disconnecting |
Reserved |
15 |
Forbidden |
Reserved |
In the following sections, we will capture packets for WireShark and analyze the Protocols one by one. Thank you for your attention.