/ informatics / network /



MQTT is a publish-subscribe-based “lightweight” messaging protocol for use on top of the TCP/IP protocol. It specified in the standard ISO/IEC PRF 20922.

The publish-subscribe messaging pattern requires a message broker. The broker is responsible for distributing messages to interested clients based on the topic of a message.




Sensor publish to topic e.g. deib/antlab/room5/temperature to MQTT broker. Clients subscribe on topic.

Topic Notation

Wildcards (+) are allowed for subscription on single topic level.


Fixed Header (2 bytes):

 0                   1           
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 
|  CPT  | Flags |RemainingLength|

Variable Length Header

Many messages include a 2 byte Packet Identifier in the variable length header.

There are 14 Control packet types (CPTs):

Name Value Direction Pack. ID Payload
Reserved 0x0 none no None
CONNECT 0x1 C → S no Req.
CONNACK 0x2 S → C yes None
PUBLISH 0x3 both yes Opt.
PUBACK 0x4 both yes None
PUBREC 0x5 both yes None
PUBREL 0x6 both yes None
PUBCOMP 0x7 both yes None
SUBSCRIBE 0x8 C → S yes Req.
SUBACK 0x9 S → C yes Req.
UNSUBSCRIBE 0xA C → S yes Req.
UNSUBACK 0xB S → C yes None
PINGREQ 0xC C → S no None
PINGRESP 0xD S → C no None
DISCONNECT 0xE both no None
AUTH 0xF both no None

CONNECT message fields:

PUBLISH message fields

Field Example
packageID 2
topicName "matteo/temp"
QoS 1
retainFlag false
Payload "temperature:30"
dupFlag false

Quality of Service (QoS)

Each connection to the broker can specify a QoS with the followin levels:


  1. ISO/IEC 20922
  2. MQTT Specification 5.0, 2019
  3. http://mqtt.org/