This topic describes optimized device-cloud interactions in MQTT 5.0 supported by IoT Platform.
Feature description
MQTT 5.0 is designed to improve the interoperability and messaging transparency between devices and servers. In MQTT 5.0, the following device-cloud interactions are optimized:
Feedback on connection establishment
Feedback on connection establishment is a negotiation mechanism between devices and the server. When a connection is being established between a device and the server, the device sends connection parameters in the request, and the server returns a CONNACK packet as the feedback. The CONNACK packet is a connect acknowledgment that includes the values of request parameters and the features that are available to the device.
CONNACK property | Description and value range | Response from IoT Platform |
Retain Available |
| 1 |
Wildcard Subscription Available |
| 1 |
Subscription Identifiers Available |
| 0 |
Shared Subscription Available |
| 1 |
Topic Alias |
| 1 |
Maximum QoS |
| 1 |
Server Keep Alive | The server continues to send heartbeat packets or data packets during the keep-alive period. Otherwise, the connection is disrupted. This property specifies the keep-alive period. Valid values: 30 to 1200. | IoT Platform returns the keep-alive period that the device specifies in the connection parameters. If the value that is set by the device is beyond the value range, the connection is disrupted. |
Session Expiry Interval | This property specifies the retention period of the session after the connection is disrupted. Valid values: 0 to 0xFFFFFFFF. | IoT Platform returns the retention period that the device specifies in the connection parameters. If the device did not specify this period, the default value 0 is used. |
Maximum Packet Size | Valid values: 0 to 0xFFFFFFFF. | IoT Platform always returns 262144, which indicates 256 KB. |
Topic Alias Maximum | Valid values: 0 to 0xFFFFFFFF. | IoT Platform always returns 20. |
Server-sent DISCONNECT packets
In MQTT 3.1.1, if a device violates a rule, the server directly closes the device connection without explaining why the connection closed.
In MQTT 5.0, the server can close the connection to a device, and sends a DISCONNECT packet to the device. The DISCONNECT packet contains a reason code and a reason string that explains why the connection closed. The DISCONNECT packet simplifies troubleshooting.
Enhancements in error codes
Enhancement | MQTT 3.1 | MQTT 5.0 |
Quantity increase | 5 error codes | 20 error codes |
Reason string | Not supported | The Reason String property is added to specify the detailed error cause for debugging and troubleshooting. |
Error codes for more types of packets | Error codes are returned for only CONNECT packets. | Error codes are returned for CONNECT, UNSUBACK, PUBACK, DISCONNECT and other packets. |
Error codes
Decimal | Hexadecimal | Name | Packet type |
0 | 0x00 | Success | CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, UNSUBACK, and AUTH |
128 | 0x80 | Unspecified error | CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, and DISCONNECT |
129 | 0x81 | Malformed Packet | CONNACK and DISCONNECT |
130 | 0x82 | Protocol Error | CONNACK and DISCONNECT |
132 | 0x84 | Unsupported Protocol Version | CONNACK |
136 | 0x88 | Server unavailable | CONNACK |
137 | 0x89 | Server busy | CONNACK and DISCONNECT |
138 | 0x8A | Banned | CONNACK |
140 | 0x8C | Bad authentication method | CONNACK and DISCONNECT |
141 | 0x8D | Keep Alive timeout | DISCONNECT |
144 | 0x90 | Topic Name invalid | CONNACK, PUBACK, PUBREC, and DISCONNECT |
147 | 0x93 | Receive Maximum exceeded | DISCONNECT |
148 | 0x94 | Topic Alias invalid | DISCONNECT |
149 | 0x95 | Packet too large | CONNACK and DISCONNECT |
150 | 0x96 | Message rate too high | DISCONNECT |
151 | 0x97 | Quota exceeded | CONNACK, PUBACK, PUBREC, SUBACK, and DISCONNECT |
152 | 0x98 | Administrative action | DISCONNECT |
153 | 0x99 | Payload format invalid | PUBACK, PUBREC, and DISCONNECT |
154 | 0x9A | Retain not supported | CONNACK and DISCONNECT |
155 | 0x9B | QoS not supported | CONNACK and DISCONNECT |
156 | 0x9C | Use another server | CONNACK and DISCONNECT |
157 | 0x9D | Server moved | CONNACK and DISCONNECT |
158 | 0x9E | Shared Subscription not supported | SUBACK and DISCONNECT |
159 | 0x9F | Connection rate exceeded | CONNACK and DISCONNECT |