We know that MQTT is a specification of an IoT protocol, and thelatest two versions of the MQTT protocol are: 3.1.1 and 3.1.0
(1) The specifications of 3.1.0 are as follows
Http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
(2) The specifications of 3.1.1 are as follows
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718029
Normative 3.1.0 and 3.1.1 still have a lot of difference. For example, in the variable head, in the 3.1.0 specification, the keyword is, "MQISDP"
Table 1. MQTT V3.1 Specification The first 8 bytes of a mutable 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 |
|
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 |
Table 2. MQTT V3.1.1 The first 6 bytes of a variable message header
|
Describe |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Agreement 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 |
|
Describe |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
BYTE 7 |
Level (4) |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
The specification mainly describes the general format of the message, the command of the message, the flow of messages, and so on. In the previous four chapters, we have a perceptual understanding of MQTT, and in the next series of articles, I will take you to the following 14 kinds of command messages for MQTT through the capture package software (WireShark) and combine the specific specifications with everyone else. Note that because I use the Java Library of the Eclipse Paho API to support the version of Mqtt 3.1.1, and Mosquitto also supports the 3.1.1 version, all of the capture packages in this series will be based on the Mqtt 3.1.1 specification, not the MQTT 3.1 specification. Please pay attention to them. The following table describes the different message types in Mqtt 14.
Table 3. 14 Message types for MQTT (Command message)
Name |
Value |
Direction of information flow |
Describe |
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 chapters we will be one to everyone with Wireshark grab bag, and give everyone an analysis of their agreement, please look forward to and attention, thank you.
[5] mqtt,mosquitto,eclipse Paho---MQTT Message Format analysis overview