wire / wire-format / mqtt-packet
MQTT (Message Queuing Telemetry Transport) packets: fixed header (1 byte: packet type 4 bits + flags 4 bits, then variable-length remaining length), then variable header (packet ID, topic name, etc.), then payload. Packet types: 1 CONNECT, 2 CONNACK, 3 PUBLISH, 4 PUBACK, 5 PUBREC, 6 PUBREL, 7 PUBCOMP, 8 SUBSCRIBE, 9 SUBACK, 10 UNSUBSCRIBE, 11 UNSUBACK, 12 PINGREQ, 13 PINGRESP, 14 DISCONNECT, 15 AUTH.
aka: MQTT packet (fixed header)
spec: OASIS MQTT 5.0
MQTT (Message Queuing Telemetry Transport) packets: fixed header (1 byte: packet type 4 bits + flags 4 bits, then variable-length remaining length), then variable header (packet ID, topic name, etc.), then payload. Packet types: 1 CONNECT, 2 CONNACK, 3 PUBLISH, 4 PUBACK, 5 PUBREC, 6 PUBREL, 7 PUBCOMP, 8 SUBSCRIBE, 9 SUBACK, 10 UNSUBSCRIBE, 11 UNSUBACK, 12 PINGREQ, 13 PINGRESP, 14 DISCONNECT, 15 AUTH.
| field | size | meaning |
|---|---|---|
| Packet type | 4 bits (high nibble of byte 0) | 1 CONNECT, 2 CONNACK, 3 PUBLISH, 4 PUBACK, 5 PUBREC, 6 PUBREL, 7 PUBCOMP, 8 SUBSCRIBE, 9 SUBACK, 10 UNSUBSCRIBE, 11 UNSUBACK, 12 PINGREQ, 13 PINGRESP, 14 DISCONNECT, 15 AUTH. |
| Flags | 4 bits (low nibble of byte 0) | PUBLISH: DUP (bit 3), QoS (bits 1-2), RETAIN (bit 0). Others: reserved (must be 0) except PUBREL/SUBSCRIBE/UNSUBSCRIBE (must be 2). |
| Remaining length | 1-4 bytes (variable-length encoding) | Number of bytes remaining in the packet (max 268,435,455). Each byte: 7 bits of data + 1 continuation bit. |
| Variable header | variable | CONNECT: protocol name, version, flags, keep alive, properties. PUBLISH: topic name, packet ID (if QoS > 0), properties. |
| Payload | variable | CONNECT: client ID, will topic, will payload, username, password. PUBLISH: application message. SUBSCRIBE: topic filters + QoS. |
example:
10 10 00 04 4d 51 54 54 05 02 00 3c 00 00 00 00
MQTT CONNECT packet: type 1, remaining length 16, protocol 'MQTT', version 5, clean start, keep alive 60
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/mqtt-packet
or /wire-format/mqtt-packet.json