Here is the Publish frame format from the MQTT protocol.
Refer to the end of the post for more information for various fields.
The official definition can be found here.

byte

content (hexa)

content

1

3

MQTT Control Packet
type

?

DUP

QoS

QoS

RETAIN

2

?

Remaining Length

?

(4 + topic_length + payload_length)

3

?

topic Length MSB

?

4

?

topic Length LSB

?

5

?

topic

?

?

?

Packet Identifier
MSB

?

?+1

?

Packet Identifier
LSB

?

?+2

?

Payload

?

MQTT Control Packet type:
This is present for each frame, it announces the coming frame

DUP:
The DUP flag MUST be set to 1 by the Client or Server when it attempts to re-deliver a PUBLISH Packet. The DUP flag MUST be set to 0 for all QoS 0 messages.
The value of the DUP flag from an incoming PUBLISH packet is not propagated when the PUBLISH. Packet is sent to subscribers by the Server. The DUP flag in the outgoing PUBLISH packet is set independently to the incoming PUBLISH packet, its value MUST be determined solely by whether the outgoing PUBLISH packet is a retransmission.
QoS:

QoS value

Bit 2

bit 1

Description

0

0

0

At most once delivery

1

0

1

At least once delivery

2

1

0

Exactly once delivery

1

1

Reserved – must not be used

RETAIN:
The RETAIN flag is present when a frame is willed to be kept for client not connected yet. If the RETAIN flag is set on 1, the frame will be kept by the broker and sent to the client when they connect.

Remaining Length:
Length of the rest of the frame. “4 + topic_length + payload_length” is the formula used to calculate this length.

Packet Identifier:
(MSB and LSB = most significant byte and least significant byte)
SUBSCRIBE, UNSUBSCRIBE, and PUBLISH (in cases where QoS > 0) Control Packets MUST contain a non-zero 16-bit Packet Identifier [MQTT-2.3.1-1]. Each time a Client sends a new packet of one of these types it MUST assign it a currently unused Packet Identifier [MQTT-2.3.1-2]. If a Client re-sends a particular Control Packet, then it MUST use the same Packet Identifier in subsequent re-sends of that packet. The Packet Identifier becomes available for reuse after the Client has processed the corresponding acknowledgement packet. In the case of a QoS 1 PUBLISH this is the corresponding PUBACK; in the case of QoS 2 it is PUBCOMP. For SUBSCRIBE or UNSUBSCRIBE it is the corresponding SUBACK or UNSUBACK [MQTT-2.3.1-3]. The same conditions apply to a Server when it sends a PUBLISH with QoS > 0.

Back Next

Publish
Tagged on:                             

4 thoughts on “Publish

Leave a Reply