MQTT 5.0 new features |(2) Reason code and ACK
MQTT v3.1.1
MQTT v3.1.1 protocol has only 10 return codes. These return codes can represent little meaning, and the same return code value can have different meanings in different messages.
CONNACK Packet
There are only 6 return codes in the CONNECT packet. Only when the return code of the CONNACK packet sent back by the server is 0, the connection is successfully established.
SUBACK Packet
There are only 4 return codes in the SUBACK packet.
There are 4 return codes in the SUBACK packet. Except that the return code 0x80 indicates failure, the other return codes indicate that the subscription is successful, and the three values 0, 1, 2 represent the maximum QoS value of the subscribed message.
MQTT v5.0
The MQTT v5.0 protocol renames the return code to a reason code, adding a reason code to indicate more types of errors.
The following table is a list of reason codes that represent the value of the reason code and the control packet containing the reason code:
The reason code is a single-byte unsigned value used to indicate the result of the operation. The reason code less than 0x80 indicates that the result of the operation is successful. Under normal circumstances, the reason code value returned by the operation is 0. If the reason code returned is greater than or equal to 0x80, the operation has failed.
The reason codes for CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, DISCONNECT and AUTH control packets are stored in the variable header. The SUBACK and UNSUBACK packets contain a list of reason codes in the payload.
Welcome to our open source project github.com/emqx/emqx. Please visit the documentation for details.