DISCONNECT
Fixed header flags: 0000 – all flags reserved
DISCONNECT signals a graceful connection closure. In MQTT 3.1.1, only the client could send DISCONNECT with no reason code. MQTT 5.0 allows both client and broker to send DISCONNECT with a reason code and optional properties. A client DISCONNECT with reason 0x00 (Normal Disconnection) tells the broker not to send the Will message.
Details
DISCONNECT in MQTT 5.0 is bidirectional – the broker can now initiate a graceful disconnect with a reason code, which was impossible in 3.1.1.
Client-sent reason codes: 0x00 = Normal Disconnection (suppress Will message) 0x04 = Disconnect With Will Message (send Will despite graceful close) 0x80 = Unspecified error 0x81 = Malformed Packet 0x82 = Protocol Error 0x89 = Keep Alive Timeout 0x8E = Session Taken Over
Broker-sent reason codes (MQTT 5.0): 0x00 = Normal Disconnection 0x80 = Unspecified error 0x81 = Malformed Packet 0x82 = Protocol Error 0x87 = Not Authorized 0x89 = Server Busy 0x8B = Server Shutting Down 0x8D = Keep Alive Timeout 0x8E = Session Taken Over (another client connected with same ID) 0x9C = Use Another Server 0x9D = Server Moved 0x98 = Connection Rate Exceeded
Will message behavior: the broker sends the Will message if the client disconnects without sending DISCONNECT (network failure, crash). A client DISCONNECT with 0x00 suppresses the Will. A client DISCONNECT with 0x04 forces the Will to be sent despite graceful close.
Fixed Header
| Field | Value |
|---|---|
| Packet type (bits 7–4) | 14 (1110₂) |
| First byte (hex) | 0xE0 |
| Flags (bits 3–0) | 0000 – all flags reserved |
| QoS bits apply | No |
| Direction | both |
| Added in | MQTT 3.1 |