MQTT - Message Queuing Telemetry Transport

What is MQTT?

MQTT stands for Message Queuing Telemetry Transport. It’s a lightweight, publish-subscribe network protocol used for messaging between devices, especially in low-bandwidth, high-latency, or unreliable networks. It’s widely used in IoT (Internet of Things) applications.

Why is MQTT useful?

MQTT is designed for efficient communication in constrained environments. It minimizes network bandwidth and device resource requirements, making it ideal for: * IoT devices (sensors, actuators) * Mobile applications * Remote monitoring systems

How it works?

  • Client connects to broker – A device (client) connects to an MQTT broker (server).

  • Client subscribes or publishes – The client either subscribes to a topic (to receive messages) or publishes a message to a topic.

  • Broker routes messages – The broker receives published messages and forwards them to all clients subscribed to the topic.

  • Clients receive messages – Subscribed clients get the message in real-time.

Where is MQTT used?

  • IoT ecosystems – Smart homes, industrial automation, agriculture.

  • Mobile messaging apps – Where low power and bandwidth are critical.

  • Remote monitoring – Oil rigs, pipelines, weather stations.

  • Healthcare – Wearable devices and patient monitoring systems.

Which OSI layer does this protocol belong to?

  • It provides messaging services to applications and devices.

  • Uses TCP (typically port 1883) for reliable delivery (or 8883 for secure TLS).

  • Implements publish/subscribe model, which is an application-level communication pattern.

What is a broker?

The broker is the central server that: * Accepts connections from clients (publishers/subscribers). * Routes messages from publishers to subscribers. * Ensures correct delivery based on topic matching and QoS (Quality of Service).

What ports does MQTT use?

  • Port 1883 – Default for MQTT over TCP (unencrypted).

  • Port 8883 – MQTT over TLS/SSL (secure).

What are MQTT topics?

Topics are string-based filters used by the broker to route messages. Example: “home/livingroom/temperature”.

What type of communication does MQTT support?

  • MQTT supports the Publish/Subscribe communication model, which enables asynchronous, decoupled messaging between devices via a central broker.

  • It allows one-way communication where publishers send messages and subscribers receive them.

  • It also supports two-way communication when clients both publish and subscribe on different topics, enabling bidirectional message exchange.

  • All communication flows through the broker — there is no direct client-to-client messaging.

What is a Publisher in MQTT?

  • A Publisher is a device or application that sends messages.

  • It decides what data to send and which topic to send it to.

  • It does not need to know who will receive the data.

What is a Subscriber in MQTT?

  • A Subscriber is a device or application that receives messages.

  • It subscribes to one or more topics of interest.

  • It only gets messages that match those topics.

What is the working flow of MQTT?

  • MQTT uses a publish/subscribe model involving three components: * Publisher: Sends messages to a specific topic. * Broker: Receives messages from publishers and routes them to subscribers. * Subscriber: Receives messages by subscribing to relevant topics.

  • Flow: * Publisher sends a message to a topic on the broker. * Broker receives the message and forwards it to all subscribers of that topic. * Subscribers receive the message asynchronously.

Does MQTT support multiple publishers and multiple subscribers?

  • Yes, MQTT fully supports multiple publishers and multiple subscribers.

  • Multiple publishers can publish messages to the same or different topics.

  • Multiple subscribers can subscribe to the same topic, and all will receive messages published to that topic.

  • The broker manages message routing, ensuring that each subscriber receives the messages they subscribed to.

  • This makes MQTT highly scalable and ideal for IoT and distributed messaging systems.

  • In this section, you are going to learn

  • Terminology

  • Version Info

MQTT Version

RFC

Year

Core Idea / Contribution

MQTT 3.1

Proprietary (IBM)

2010

First public version of MQTT, designed for lightweight M2M communication.

MQTT 3.1.1

OASIS Standard

2014

Improved interoperability, clarified ambiguities, added UTF-8 support Widely adopted.

MQTT 5.0

OASIS Standard

2019

Major upgrade: added properties, reason codes, shared subscriptions, session expiry, and enhanced error reporting.

MQTT-SN 1.2

Informational (OASIS)

2020

MQTT for Sensor Networks optimized for non-TCP/IP networks like Zigbee.

MQTT-TLS Profile (ACE)

RFC 9431

2023

Defines secure authentication and authorization using OAuth 2.0 and TLS for constrained environments

Server (Machine A) — Broker Setup (IPv4)

  • Step-1 : Find the IP address of Ubuntu machine

    test:~$ ifconfig
    
    docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
    ether 02:42:c2:a4:22:08  txqueuelen 0  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    wlx503eaa8c24ae: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.0.31  netmask 255.255.255.0  broadcast 192.168.0.255
    inet6 fd8d::7bbc:1295:8:db53:73a2:97c0:2dc2  prefixlen 64  scopeid 0x0<global>
    ether e4:54:e8:4e:e4:b9  txqueuelen 1000  (Ethernet)
    RX packets 10426884  bytes 7818062595 (7.8 GB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 3605750  bytes 434038103 (434.0 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 16  memory 0xdf000000-df020000
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1000  (Local Loopback)
    RX packets 1097677  bytes 88297298 (88.2 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 1097677  bytes 88297298 (88.2 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

Note

  • To find the IP address of your Ubuntu machine,use the ifconfig command.

  • From the output of ifconfig command,for example, 192.168.0.31 is used as the Server IPv4.

  • This server IPv4 is used when connecting MQTT server to a client.

  • Step-2 : Install Mosquitto Broker on Ubuntu

    test:~$ pwd
    /home/test
    
    test:~$ sudo apt update
    
    test:~$ sudo apt install mosquitto mosquitto-clients
    
  • Step-3 : Edit the Mosquitto Configuration file

    test:~$ sudo nano /etc/mosquitto/mosquitto.conf
    listener 1883 0.0.0.0
    allow_anonymous true
    

    Note

    • 0.0.0.0 listens on all IPv4 interfaces

  • Step-4 : Start the mosquitto server

    test:~$ sudo systemctl restart mosquitto
    test:~$ sudo systemctl enable mosquitto
    test:~$ sudo systemctl status mosquitto
    

    Note

    If server is not running,check logs at “sudo journalctl -u mosquitto” or “sudo systemctl status mosquitto” and fix the errors.

  • Step-5 : Allow connection from port 1883 (MQTT port)

    test:~$ sudo ufw allow 1883
    test:~$ sudo ufw reload
    
  • Step-6 : To check the server is listening on port

    test:~$ sudo netstat -tuln | grep 1883
    tcp   0   0 0.0.0.0:1883   0.0.0.0:*   LISTEN
    
  • Step-7 : To view the logs

    test:~$ sudo tail -f /var/log/mosquitto/mosquitto.log
    

Client (Machine B) — MQTT Client Setup (IPv4)(One-way Communication(Publisher->subscriber))

  • Step-1 : Install MQTT Client Tools

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity

    test:~$ ping 192.168.0.31
    PING 192.168.0.31 (192.168.0.31 56(84) bytes of data.
    64 bytes from 192.168.0.31: icmp_seq=1 ttl=64 time=0.092 ms
    64 bytes from 192.168.0.31: icmp_seq=2 ttl=64 time=0.036 ms
    64 bytes from 192.168.0.31: icmp_seq=3 ttl=64 time=0.094 ms
    64 bytes from 192.168.0.31: icmp_seq=4 ttl=64 time=0.105 ms
    64 bytes from 192.168.0.31: icmp_seq=5 ttl=64 time=0.094 ms
    

    Note

    192.168.0.31 is the Server IPv4 address referenced in the “IPv4 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t test/topic
    
  • Keep this terminal open ,it waits for messages.

  • Step-4 : Publish Message

  • In a new terminal on client:

test:~$ mosquitto_pub -h 192.168.0.31 -p 1883 -t test/topic -m "Hello IPv4"
  • Expected output : You should see the message on the subscriber terminal.

    test:~$mosquitto_sub -h 192.168.0.31 -p 1883 -t test/topic
    Hello IPv4
    
  • Step-5 : Wireshark Capture

    Download wireshark capture

Client (Machine B),Client (Machine C) — MQTT Client Setup (IPv4)(Two-way Communication(Publisher<->subscriber))

  • Step-1 : Install MQTT Client Tools in both Client Machines(B & C)

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity in both Client Machines(B & C)

    test:~$ ping 192.168.0.31
    PING 192.168.0.31 (192.168.0.31 56(84) bytes of data.
    64 bytes from 192.168.0.31: icmp_seq=1 ttl=64 time=0.092 ms
    64 bytes from 192.168.0.31: icmp_seq=2 ttl=64 time=0.036 ms
    64 bytes from 192.168.0.31: icmp_seq=3 ttl=64 time=0.094 ms
    64 bytes from 192.168.0.31: icmp_seq=4 ttl=64 time=0.105 ms
    64 bytes from 192.168.0.31: icmp_seq=5 ttl=64 time=0.094 ms
    

    Note

    192.168.0.31 is the Server IPv4 address referenced in the “IPv4 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic BtoA in Client (Machine B)

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/BtoA
    
  • Keep this terminal open ,it waits for messages.

  • Step-4 : Subscribe to Topic AtoB in Client (Machine C)

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/AtoB
    
  • Keep this terminal open ,it waits for messages.

  • Step-5 : Publish Message BtoA in Client (Machine C)

  • In a new terminal on client (Machine C):

test:~$  mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/BtoA -m "Hi from B"
  • Expected output : You should see the message on the subscriber terminal.

    test:~$  mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/BtoA
    Hi from B
    
  • Step-6 : Publish Message AtoB in Client (Machine B)

  • In a new terminal on client (Machine B):

test:~$ mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/AtoB -m "Hello from A"
  • Expected output : You should see the message on the subscriber terminal.

    test:~$  mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/AtoB
    Hello from A
    
  • Step-7 : Wireshark Capture

    Download wireshark capture

Client (Machine B) — MQTT Client Setup (IPv4)(One-way Communication(Publisher->subscriber))

  • Step-1 : Install MQTT Client Tools

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity

    test:~$ ping 192.168.0.31
    PING 192.168.0.31 (192.168.0.31 56(84) bytes of data.
    64 bytes from 192.168.0.31: icmp_seq=1 ttl=64 time=0.092 ms
    64 bytes from 192.168.0.31: icmp_seq=2 ttl=64 time=0.036 ms
    64 bytes from 192.168.0.31: icmp_seq=3 ttl=64 time=0.094 ms
    64 bytes from 192.168.0.31: icmp_seq=4 ttl=64 time=0.105 ms
    64 bytes from 192.168.0.31: icmp_seq=5 ttl=64 time=0.094 ms
    

    Note

    192.168.0.31 is the Server IPv4 address referenced in the “IPv4 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic one

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/one
    
    • Keep this terminal open ,it waits for messages.

  • Step-4 : Subscribe to Topic two

    • In a new terminal on client:

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/two
    
    • Keep this terminal open ,it waits for messages.

  • Step-5 : Subscribe to Topic three

    • In a new terminal on client:

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/three
    
    • Keep this terminal open ,it waits for messages.

  • Step-6 : Subscribe to Topic four

    • In a new terminal on client:

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/four
    
    • Keep this terminal open ,it waits for messages.

  • Step-7 : Publish Message topic one

    • In a new terminal on client:

    test:~$  mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/one -m "Message from Pub1"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/one
    Message from Pub1
    
  • Step-8 : Publish Message topic two

    • In a new terminal on client:

    test:~$  mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/one -m "Message from Pub2"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/two
    Message from Pub2
    
  • Step-9 : Publish Message topic three

    • In a new terminal on client:

    test:~$  mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/one -m "Message from Pub3"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/three
    Message from Pub3
    
  • Step-10 : Publish Message topic four

    • In a new terminal on client:

    test:~$  mosquitto_pub -h 192.168.0.31 -p 1883 -t topic/one -m "Message from Pub4"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h 192.168.0.31 -p 1883 -t topic/four
    Message from Pub4
    

Server (Machine A) — Broker Setup (IPv6)

  • Step-1 : Find the IP address of Ubuntu machine

    test:~$ ifconfig
    
    docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
    ether 02:42:c2:a4:22:08  txqueuelen 0  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    wlx503eaa8c24ae: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.0.31  netmask 255.255.255.0  broadcast 192.168.0.255
    inet6 fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 prefixlen 64  scopeid 0x0<global>
    ether e4:54:e8:4e:e4:b9  txqueuelen 1000  (Ethernet)
    RX packets 10426884  bytes 7818062595 (7.8 GB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 3605750  bytes 434038103 (434.0 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 16  memory 0xdf000000-df020000
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1000  (Local Loopback)
    RX packets 1097677  bytes 88297298 (88.2 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 1097677  bytes 88297298 (88.2 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

Note

  • To find the IP address of your Ubuntu machine,use the ifconfig command.

  • From the output of ifconfig command,for example, fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 is used as the Server IPv6.

  • This server IPv6 is used when connecting MQTT server to a client.

  • Step-2 : Install Mosquitto Broker on Ubuntu

    test:~$ pwd
    /home/test
    
    test:~$ sudo apt update
    
    test:~$ sudo apt install mosquitto mosquitto-clients
    
  • Step-3 : Edit the Mosquitto Configuration file

    test:~$ sudo nano /etc/mosquitto/mosquitto.conf
    listener 1883 ::
    allow_anonymous true
    

    Note

    • :: listens on all IPv6 interfaces

  • Step-4 : Start the mosquitto server

    test:~$ sudo systemctl restart mosquitto
    test:~$ sudo systemctl enable mosquitto
    test:~$ sudo systemctl status mosquitto
    

    Note

    If server is not running,check logs at “sudo journalctl -u mosquitto” or “sudo systemctl status mosquitto” and fix the errors.

  • Step-5 : Allow connection from port 1883 (MQTT port)

    test:~$ sudo ufw allow 1883
    test:~$ sudo ufw reload
    
  • Step-6 : To check the server is listening on port

    test:~$ sudo netstat -tuln | grep 1883
    tcp6   0   0 :::1883   :::*   LISTEN
    
  • Step-7 : To view the logs

    test:~$ sudo tail -f /var/log/mosquitto/mosquitto.log
    

Client (Machine B) — MQTT Client Setup (IPv6)(One-way Communication(Publisher->Subscriber))

  • Step-1 : Install MQTT Client Tools

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity

    test:~$ ping6 fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2
    PING fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2(fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2) 56 data bytes
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=1 ttl=64 time=342 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=2 ttl=64 time=46.2 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=3 ttl=64 time=63.4 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=4 ttl=64 time=8.95 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=5 ttl=64 time=12.6 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=6 ttl=64 time=14.0 ms
    

    Note

    fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 is the Server IPv6 address referenced in the “IPv6 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -t test/topic
    
  • Keep this terminal open ,it waits for messages.

  • Step-4 : Publish Message

    • In a new terminal on client:

    test:~$ mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t test/topic -m "Hello from client it is ipv6 address"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -t test/topic
    Hello from client it is ipv6 address
    
  • Step-5 : Wireshark Capture

    Download wireshark capture

Client (Machine B),Client (Machine c) — MQTT Client Setup (IPv6)(Two-way Communication(Publisher<->Subscriber))

  • Step-1 : Install MQTT Client Tools in both Machines (B & C)

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity in both Machines (B & C)

    test:~$ ping6 fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2
    PING fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2(fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2) 56 data bytes
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=1 ttl=64 time=342 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=2 ttl=64 time=46.2 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=3 ttl=64 time=63.4 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=4 ttl=64 time=8.95 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=5 ttl=64 time=12.6 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=6 ttl=64 time=14.0 ms
    

    Note

    fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 is the Server IPv6 address referenced in the “IPv6 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic BtoA in Client (Machine B)

    test:~$ mosquitto_sub -fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2c2 -p 1883 -t topic/BtoA
    
  • Keep this terminal open ,it waits for messages.

  • Step-4 : Subscribe to Topic AtoB in Client (Machine C)

    test:~$ mosquitto_sub -fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2c2 -p 1883 -t topic/AtoB
    
  • Keep this terminal open ,it waits for messages.

  • Step-5 : Publish Message BtoA in Client (Machine C)

    • In a new terminal on client (Machine C):

    test:~$ mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/BtoA -m "Hi from B"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/BtoA
    Hi from B
    
  • Step-6 : Publish Message AtoB in Client (Machine B)

    • In a new terminal on client (Machine B):

    test:~$ mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/AtoB -m "Hello from A"
    
  • Expected output : You should see the message on the subscriber terminal.

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/AtoB
    Hello from A
    
  • Step-7 : Wireshark Capture

    Download wireshark capture

Client (Machine B) — MQTT Client Setup (IPv6)(one-way Communication(Publisher->Subscriber))

  • Step-1 : Install MQTT Client Tools

    test:~$ sudo apt update
    test:~$ sudo apt install mosquitto-clients
    
  • Step-2 : Test Network Connectivity

    test:~$ ping6 fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2
    PING fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2(fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2) 56 data bytes
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=1 ttl=64 time=342 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=2 ttl=64 time=46.2 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=3 ttl=64 time=63.4 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=4 ttl=64 time=8.95 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=5 ttl=64 time=12.6 ms
    64 bytes from fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2: icmp_seq=6 ttl=64 time=14.0 ms
    

    Note

    fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 is the Server IPv6 address referenced in the “IPv6 Basic Setup on Ubuntu” section above.

  • Step-3 : Subscribe to Topic one

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one
    
    • Keep this terminal open ,it waits for messages.

  • Step-4 : Subscribe to Topic two

    • In a new terminal on client:

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/two
    
    • Keep this terminal open ,it waits for messages.

  • Step-5 : Subscribe to Topic three

    • In a new terminal on client:

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/three
    
    • Keep this terminal open ,it waits for messages.

  • Step-6 : Subscribe to Topic four

    • In a new terminal on client:

    test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/four
    
    • Keep this terminal open ,it waits for messages.

  • Step-7 : Publish Message topic one

    • In a new terminal on client:

    test:~$  mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one -m "Message from Pub1"
    
  • Expected output : You should see the message on the subscriber terminal.

test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one
Message from Pub1
  • Step-8 : Publish Message topic two

    • In a new terminal on client:

    test:~$  mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one -m "Message from Pub2"
    
  • Expected output : You should see the message on the subscriber terminal.

test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/two
Message from Pub2
  • Step-9 : Publish Message topic three

    • In a new terminal on client:

    test:~$  mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one -m "Message from Pub3"
    
  • Expected output : You should see the message on the subscriber terminal.

test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/three
Message from Pub3
  • Step-10 : Publish Message topic four

    • In a new terminal on client:

test:~$  mosquitto_pub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/one -m "Message from Pub4"
  • Expected output : You should see the message on the subscriber terminal

test:~$ mosquitto_sub -h fd8d:7bbc:1295:8:db53:73a2:97c0:2dc2 -p 1883 -t topic/four
Message from Pub4

MQTT CONNECT Packet

S.No

Protocol Packets

Description

Size(bytes)

1

MQTT CONNECT Packet

Client request to connect to the MQTT broker

Varies (minimum ~12 bytes + payload)

Fixed Header

Packet Type (1 for CONNECT), Flags, Remaining Length

2+

Protocol Name

MQTT (length-prefixed UTF-8 string)

6

Protocol Level

MQTT version (4 for 3.1.1, 5 for 5.0)

1

Connect Flags

Flags for Clean Session, Will, Username, Password

1

Keep Alive

Time interval in seconds

2

Properties (MQTT 5.0 only)

Optional metadata

Variable

Client Identifier

Unique ID for client

Variable

Will Topic (optional)

Topic for last will message

Variable

Will Message (optional)

Message content

Variable

Username (optional)

Username for authentication

Variable

Password (optional)

Password for authentication

Variable

MQTT CONNACK Packet

S.No

Protocol Packets

Description

Size(bytes)

2

MQTT CONNACK Packet

Acknowledgment from broker to clients CONNECT request

4 (MQTT 3.1.1)or more(MQTT 5.0)

Fixed Header

Packet Type (2 for CONNACK), Remaining Length

2

Connect Acknowledge Flags

Session Present flag

1

Connect Return Code / Reason Code

Connection status (0 = success)

1

Properties (MQTT 5.0 only)

Optional metadata

Variable

PUBLISH Packet

S.No

Protocol Packets

Description

Size(bytes)

3

PUBLISH Packet

Publish message to a topic

Varies

Fixed Header

Packet type + QoS + DUP + Retain + Remaining Length

2+

Topic Name

UTF-8 encoded topic

Variable

Packet Identifier

Required for QoS 1 and 2

2

Properties (MQTT 5.0 only)

Optional metadata

Variable

Payload

Actual message content

Variable

SUBSCRIBE Packet

S.No

Protocol Packets

Description

Size(bytes)

4

SUBSCRIBE Packet

Client subscribes to topics

Varies

Fixed Header

Packet type + Remaining Length

2+

Packet Identifier

Unique ID for this packet

2

Properties (MQTT 5.0 only)

Optional metadata

Variable

Topic Filters + QoS

List of topics and QoS levels

Variable

SUBACK Packet

S.No

Protocol Packets

Description

Size(bytes)

5

SUBACK Packet

Acknowledgment of SUBSCRIBE

Varies

Fixed Header

Packet type + Remaining Length

2+

Packet Identifier

Matches SUBSCRIBE packet

2

Properties (MQTT 5.0 only)

Optional metadata

Variable

Return Codes

One per topic filter

Variable

PUBACK Packet

S.No

Protocol Packets

Description

Size(bytes)

6

PUBACK Packet

Acknowledgment for QoS 1 PUBLISH

4+

Fixed Header

Packet Type (4), Remaining Length

2

Packet Identifier

ID of acknowledged PUBLISH

2

Reason Code

Success or failure

1

Properties

Optional (MQTT 5.0 only)

Variable

PUBREC Packet

S.No

Protocol Packets

Description

Size(bytes)

7

PUBREC Packet

Received acknowledgment for QoS 2 PUBLISH

4+

Fixed Header

Packet Type (5), Remaining Length

2

Packet Identifier

ID of received PUBLISH

2

Reason Code

Success or failure

1

Properties

Optional (MQTT 5.0 only)

Variable

PUBREL Packet

S.No

Protocol Packets

Description

Size(bytes)

8

PUBREL Packet

Release message for QoS 2 flow

4+

Fixed Header

Packet Type (6), Remaining Length

2

Packet Identifier

ID of released message

2

Reason Code

Success or failure

1

Properties

Optional (MQTT 5.0 only)

Variable

S.no

Use Case

Description

1

Smart Home Automation

MQTT enables communication between smart devices like lights, thermostats, and sensors for real-time control and automation.

2

Industrial IoT (IIoT)

Used in factories for monitoring machinery, predictive maintenance, and real-time analytics with low latency.

3

Connected Vehicles

Facilitates vehicle-to-cloud communication for telemetry, diagnostics, and infotainment systems.

4

Healthcare Monitoring

Supports wearable devices and remote patient monitoring systems by transmitting health data securely and efficiently.

5

Agriculture & Farming

Enables smart irrigation, soil monitoring, and livestock tracking using sensors and MQTT-based gateways.

6

Energy Management

Used in smart grids and solar systems to monitor energy usage, battery levels, and grid status.

7

Retail & Supply Chain

Tracks inventory, monitors refrigeration units, and manages logistics in real-time.

8

Smart Cities

Powers applications like traffic monitoring, waste management, and environmental sensors.

9

Asset Tracking

Provides real-time location and condition updates for logistics and fleet management.

10

Remote Monitoring & Control

Used in oil rigs, pipelines, and remote stations to monitor and control equipment over unreliable networks.

S.no

Feature

Description

1

Lightweight Protocol

Designed for low-bandwidth, high-latency, or unreliable networks, making it ideal for IoT.

2

Publish/Subscribe Model

Decouples message producers (publishers) and consumers (subscribers) for scalable communication.

3

Quality of Service (QoS)

Offers three levels (0, 1, 2) to ensure message delivery reliability based on application needs.

4

Retained Messages

Broker stores the last message on a topic and delivers it to new subscribers immediately.

5

Persistent Sessions

Maintains client subscriptions and undelivered messages across reconnects.

6

Small Code Footprint

Suitable for embedded systems and constrained devices.

7

Bi-directional Communication

Supports both client-to-server and server-to-client messaging.

8

Security via TLS

Supports secure communication using TLS/SSL encryption.

9

Extensible with MQTT 5.0

Adds features like user properties, reason codes, and enhanced error reporting.

Lightweight Protocol - Testcases

#

Test Case

Description

Expected Result

1

Connect with Low Bandwidth

Connect client over a low-bandwidth network

Connection succeeds

2

Publish with Low Bandwidth

Publish message over low-bandwidth

Message is delivered

3

Subscribe with Low Bandwidth

Subscribe to topic over low-bandwidth

Subscription succeeds

4

Connect with High Latency

Connect client with simulated high latency

Connection succeeds

5

Publish with High Latency

Publish message with high latency

Message is delivered

6

Subscribe with High Latency

Subscribe with high latency

Subscription succeeds

7

Connect with Packet Loss

Connect with simulated packet loss

Connection retries and succeeds

8

Publish with Packet Loss

Publish with packet loss

Message is retried or dropped based on QoS

9

Subscribe with Packet Loss

Subscribe with packet loss

Subscription succeeds

10

Connect with Intermittent Network

Connect with unstable network

Connection is re-established

11

Publish with Intermittent Network

Publish during network drop

Message is queued or retried

12

Subscribe with Intermittent Network

Subscribe during network drop

Subscription resumes

13

Connect with Cellular Network

Connect over 2G/3G/4G

Connection succeeds

14

Publish with Cellular Network

Publish over mobile network

Message is delivered

15

Subscribe with Cellular Network

Subscribe over mobile network

Subscription succeeds

16

Connect with Satellite Link

Connect over satellite internet

Connection succeeds

17

Publish with Satellite Link

Publish over satellite

Message is delivered

18

Subscribe with Satellite Link

Subscribe over satellite

Subscription succeeds

19

Connect with Wi-Fi

Connect over Wi-Fi

Connection succeeds

20

Publish with Wi-Fi

Publish over Wi-Fi

Message is delivered

21

Subscribe with Wi-Fi

Subscribe over Wi-Fi

Subscription succeeds

22

Connect with Ethernet

Connect over wired network

Connection succeeds

23

Publish with Ethernet

Publish over wired network

Message is delivered

24

Subscribe with Ethernet

Subscribe over wired network

Subscription succeeds

25

Connect with VPN

Connect over VPN

Connection succeeds

26

Publish with VPN

Publish over VPN

Message is delivered

27

Subscribe with VPN

Subscribe over VPN

Subscription succeeds

28

Connect with NAT

Connect behind NAT

Connection succeeds

29

Publish with NAT

Publish behind NAT

Message is delivered

30

Subscribe with NAT

Subscribe behind NAT

Subscription succeeds

31

Connect with IPv6

Connect using IPv6

Connection succeeds

32

Publish with IPv6

Publish using IPv6

Message is delivered

33

Subscribe with IPv6

Subscribe using IPv6

Subscription succeeds

34

Connect with IPv4

Connect using IPv4

Connection succeeds

35

Publish with IPv4

Publish using IPv4

Message is delivered

36

Subscribe with IPv4

Subscribe using IPv4

Subscription succeeds

37

Connect with TLS

Secure connection with TLS

Connection succeeds

38

Publish with TLS

Publish over TLS

Message is encrypted and delivered

39

Subscribe with TLS

Subscribe over TLS

Subscription succeeds

40

Connect with Minimal Payload

Connect with small message size

Message is delivered

41

Publish with Minimal Payload

Publish 1-byte message

Message is delivered

42

Subscribe with Minimal Payload

Subscribe to topic with small payload

Subscription succeeds

43

Connect with QoS 0

Connect using QoS 0

Message is delivered once, no retry

44

Publish with QoS 0

Publish using QoS 0

Message is delivered best-effort

45

Publish with QoS 1

Publish using QoS 1

Message is delivered at least once

46

Publish with QoS 2

Publish using QoS 2

Message is delivered exactly once

47

Connect with Clean Session

Connect with clean session flag

No session state retained

48

Connect with Persistent Session

Connect with persistent session

Session state is retained

49

Connect with Keep Alive

Use keep-alive interval

Connection is maintained

50

Connect with Will Message

Use last will message

Will message is sent on disconnect

Publish/Subscribe Model - Testcases

#

Test Case

Description

Expected Result

1

Basic Publish

Publish message to a topic

Message is accepted by broker

2

Basic Subscribe

Subscribe to a topic

Subscription is acknowledged

3

Publish and Receive

Publish and receive message

Subscriber receives message

4

Multiple Subscribers

Multiple clients subscribe to same topic

All receive published message

5

Multiple Publishers

Multiple clients publish to same topic

All messages are delivered

6

Unsubscribe from Topic

Unsubscribe from topic

No further messages received

7

Publish Without Subscriber

Publish to topic with no subscribers

Message is discarded (unless retained)

8

Subscribe Without Publisher

Subscribe to topic with no publisher

No messages received until published

9

Wildcard Subscription (+)

Subscribe using single-level wildcard

Messages from matching topics received

10

Wildcard Subscription (#)

Subscribe using multi-level wildcard

Messages from all subtopics received

11

Topic Hierarchy

Use hierarchical topic structure

Messages routed correctly

12

Retained Message

Publish retained message

New subscribers receive last retained message

13

QoS 0 Publish/Subscribe

Use QoS 0 for pub/sub

Message delivered best-effort

14

QoS 1 Publish/Subscribe

Use QoS 1 for pub/sub

Message delivered at least once

15

QoS 2 Publish/Subscribe

Use QoS 2 for pub/sub

Message delivered exactly once

16

Clean Session

Connect with clean session

No previous subscriptions retained

17

Persistent Session

Connect with persistent session

Subscriptions retained

18

Offline Subscriber

Subscriber offline during publish

Message delivered on reconnect (if QoS > 0 and persistent session)

19

Offline Publisher

Publisher offline

No messages published

20

Broker Restart

Restart broker during pub/sub

Messages resume after reconnect

21

Client Disconnect

Disconnect client during pub/sub

Messages resume after reconnect

22

Publish Large Payload

Publish large message

Message delivered if within broker limits

23

Subscribe to Nonexistent Topic

Subscribe to topic with no publisher

No messages received until published

24

Publish to Nonexistent Topic

Publish to topic with no subscribers

Message discarded unless retained

25

Subscribe with Shared Subscription

Use shared subscription

Load balanced among subscribers

26

Publish with Delay

Delay between publish and subscribe

Subscriber receives message if retained or persistent

27

Subscribe with Delay

Delay between subscribe and publish

Subscriber receives future messages

28

Publish with Authentication

Publish with valid credentials

Message accepted

29

Subscribe with Authentication

Subscribe with valid credentials

Subscription accepted

30

Publish with Invalid Credentials

Publish with invalid credentials

Access denied

31

Subscribe with Invalid Credentials

Subscribe with invalid credentials

Access denied

32

Publish with TLS

Publish over secure connection

Message encrypted and delivered

33

Subscribe with TLS

Subscribe over secure connection

Subscription encrypted and acknowledged

34

Publish from IoT Device

Publish from constrained device

Message delivered

35

Subscribe from IoT Device

Subscribe from constrained device

Messages received

36

Publish from Mobile App

Publish from mobile client

Message delivered

37

Subscribe from Mobile App

Subscribe from mobile client

Messages received

38

Publish from Web App

Publish from browser

Message delivered

39

Subscribe from Web App

Subscribe from browser

Messages received

40

Publish with JSON Payload

Publish structured data

Payload received intact

41

Subscribe with JSON Parsing

Parse JSON message

Data parsed successfully

42

Publish with Binary Payload

Publish binary data

Payload received intact

43

Subscribe with Binary Handling

Handle binary message

Data processed correctly

44

Publish to Multiple Topics

Publish to different topics

Messages routed correctly

45

Subscribe to Multiple Topics

Subscribe to multiple topics

Messages from all topics received

46

Publish with Topic Alias

Use topic aliasing

Message delivered using alias

47

Subscribe with Topic Alias

Receive message via alias

Message routed correctly

48

Publish with Message Expiry

Set message expiry interval

Message discarded after expiry

49

Subscribe After Expiry

Subscribe after message expiry

Message not received

50

Publish/Subscribe Performance Test

Measure latency and throughput

Low latency and high throughput observed

Quality of Service(QoS) - Testcases

#

Test Case

Description

Expected Result

1

Publish with QoS 0

Publish message with QoS 0

Message delivered best-effort

2

Publish with QoS 1

Publish message with QoS 1

Message delivered at least once

3

Publish with QoS 2

Publish message with QoS 2

Message delivered exactly once

4

Subscribe with QoS 0

Subscribe to topic with QoS 0

Messages received with best-effort

5

Subscribe with QoS 1

Subscribe to topic with QoS 1

Messages received at least once

6

Subscribe with QoS 2

Subscribe to topic with QoS 2

Messages received exactly once

7

QoS 0 with Packet Loss

Simulate packet loss during QoS 0 publish

Message may be lost

8

QoS 1 with Packet Loss

Simulate packet loss during QoS 1 publish

Message is retried

9

QoS 2 with Packet Loss

Simulate packet loss during QoS 2 publish

Message is retransmitted and deduplicated

10

QoS 0 with Network Delay

Publish with high latency

Message may be delayed or lost

11

QoS 1 with Network Delay

Publish with high latency

Message is eventually delivered

12

QoS 2 with Network Delay

Publish with high latency

Message is delivered once

13

QoS 0 with Broker Restart

Restart broker during publish

Message may be lost

14

QoS 1 with Broker Restart

Restart broker during publish

Message is redelivered

15

QoS 2 with Broker Restart

Restart broker during publish

Message is delivered once after recovery

16

QoS 0 with Client Disconnect

Disconnect client after publish

Message may be lost

17

QoS 1 with Client Disconnect

Disconnect client after publish

Message is retried after reconnect

18

QoS 2 with Client Disconnect

Disconnect client after publish

Message is delivered once after reconnect

19

QoS 0 with Retained Message

Publish retained message

Delivered once to new subscribers

20

QoS 1 with Retained Message

Publish retained message

Delivered at least once to new subscribers

21

QoS 2 with Retained Message

Publish retained message

Delivered exactly once to new subscribers

22

QoS 0 with Clean Session

Connect with clean session

No message persistence

23

QoS 1 with Clean Session

Connect with clean session

Messages may be redelivered

24

QoS 2 with Clean Session

Connect with clean session

Messages delivered once

25

QoS 0 with Persistent Session

Connect with persistent session

No message persistence

26

QoS 1 with Persistent Session

Connect with persistent session

Messages redelivered after reconnect

27

QoS 2 with Persistent Session

Connect with persistent session

Messages delivered once after reconnect

28

QoS 0 with Shared Subscription

Use shared subscription

Message delivered to one subscriber

29

QoS 1 with Shared Subscription

Use shared subscription

Message delivered at least once to one subscriber

30

QoS 2 with Shared Subscription

Use shared subscription

Message delivered exactly once to one subscriber

31

QoS 0 with Wildcard Topic

Subscribe using wildcard

Messages received with best-effort

32

QoS 1 with Wildcard Topic

Subscribe using wildcard

Messages received at least once

33

QoS 2 with Wildcard Topic

Subscribe using wildcard

Messages received exactly once

34

QoS 0 with Mobile Client

Publish from mobile device

Message may be lost

35

QoS 1 with Mobile Client

Publish from mobile device

Message is retried

36

QoS 2 with Mobile Client

Publish from mobile device

Message delivered once

37

QoS 0 with IoT Device

Publish from constrained device

Message may be lost

38

QoS 1 with IoT Device

Publish from constrained device

Message is retried

39

QoS 2 with IoT Device

Publish from constrained device

Message delivered once

40

QoS 0 with TLS

Publish over TLS

Message may be lost

41

QoS 1 with TLS

Publish over TLS

Message is retried

42

QoS 2 with TLS

Publish over TLS

Message delivered once

43

QoS 0 with Broker Cluster

Publish to clustered broker

Message may be lost

44

QoS 1 with Broker Cluster

Publish to clustered broker

Message is retried

45

QoS 2 with Broker Cluster

Publish to clustered broker

Message delivered once

46

QoS 0 with Message Expiry

Set expiry interval

Message may expire before delivery

47

QoS 1 with Message Expiry

Set expiry interval

Message may be retried before expiry

48

QoS 2 with Message Expiry

Set expiry interval

Message delivered once before expiry

49

QoS 1 with Duplicate Detection

Detect duplicate messages

Duplicates handled by client

50

QoS 2 with Duplicate Detection

Detect duplicate messages

No duplicates received

Retained Messages - Testcases

#

Test Case

Description

Expected Result

1

Publish Retained Message

Publish message with retain flag

Broker stores the message

2

Subscribe After Retained Publish

Subscribe after retained message is published

Subscriber receives retained message

3

Subscribe Before Retained Publish

Subscribe before retained message is published

Subscriber does not receive retained message

4

Update Retained Message

Publish new retained message

Broker replaces old retained message

5

Clear Retained Message

Publish empty message with retain flag

Broker clears retained message

6

Retained Message with QoS 0

Publish retained message with QoS 0

Message stored and delivered best-effort

7

Retained Message with QoS 1

Publish retained message with QoS 1

Message stored and delivered at least once

8

Retained Message with QoS 2

Publish retained message with QoS 2

Message stored and delivered exactly once

9

Retained Message with Wildcard Topic

Subscribe using wildcard

Retained messages from matching topics received

10

Retained Message with Shared Subscription

Use shared subscription

One subscriber receives retained message

11

Retained Message with Clean Session

Connect with clean session

Retained message delivered

12

Retained Message with Persistent Session

Connect with persistent session

Retained message delivered

13

Retained Message with Offline Subscriber

Subscriber offline during publish

Retained message delivered on reconnect

14

Retained Message with Broker Restart

Restart broker after publish

Retained message persists

15

Retained Message with Client Reconnect

Reconnect client

Retained message delivered again

16

Retained Message with Multiple Topics

Publish retained messages to multiple topics

Each topic stores its own retained message

17

Retained Message with JSON Payload

Publish retained JSON message

JSON message delivered intact

18

Retained Message with Binary Payload

Publish retained binary message

Binary message delivered intact

19

Retained Message with Large Payload

Publish large retained message

Message stored and delivered

20

Retained Message with Small Payload

Publish small retained message

Message stored and delivered

21

Retained Message with Mobile Client

Publish from mobile device

Message retained and delivered

22

Retained Message with IoT Device

Publish from constrained device

Message retained and delivered

23

Retained Message with Web Client

Publish from browser

Message retained and delivered

24

Retained Message with TLS

Publish over secure connection

Message retained securely

25

Retained Message with Authentication

Publish with valid credentials

Message retained

26

Retained Message with Invalid Auth

Publish with invalid credentials

Message rejected

27

Retained Message with Topic Alias

Publish using topic alias

Retained message stored correctly

28

Retained Message with Expiry Interval

Set expiry interval

Message expires after interval

29

Retained Message with QoS Downgrade

Subscribe with lower QoS

Message delivered at subscribers QoS

30

Retained Message with QoS Upgrade

Subscribe with higher QoS

Message delivered at publishers QoS

31

Retained Message with Broker Cluster

Publish to clustered broker

Retained message replicated

32

Retained Message with NAT

Publish behind NAT

Message retained and delivered

33

Retained Message with VPN

Publish over VPN

Message retained and delivered

34

Retained Message with IPv4

Publish using IPv4

Message retained and delivered

35

Retained Message with IPv6

Publish using IPv6

Message retained and delivered

36

Retained Message with Topic Hierarchy

Publish to hierarchical topic

Retained message stored at each level

37

Retained Message with Broker Limits

Publish near brokers retained limit

Message retained if within limits

38

Retained Message with Broker Policy

Publish with broker policy restrictions

Message retained or rejected based on policy

39

Retained Message with Logging Enabled

Enable broker logging

Retained message logged

40

Retained Message with Audit Trail

Review audit logs

Retained message history visible

41

Retained Message with Monitoring Tool

Monitor retained message delivery

Message delivery confirmed

42

Retained Message with GUI Client

Publish from GUI

Message retained and visible

43

Retained Message with CLI Client

Publish from CLI

Message retained and visible

44

Retained Message with Broker Crash

Crash broker after publish

Retained message persists

45

Retained Message with Client Crash

Crash client after publish

Message retained on broker

46

Retained Message with Duplicate Topic

Publish to same topic repeatedly

Last message retained

47

Retained Message with QoS Mismatch

QoS mismatch between publisher and subscriber

Message delivered at subscribers QoS

48

Retained Message with Topic Filter

Subscribe with topic filter

Retained message delivered if matched

49

Retained Message with Message History

Check previous retained messages

Only last message retained

50

Retained Message Performance Test

Measure delivery time to new subscriber

Immediate delivery observed

Persistent Sessions - Testcases

#

Test Case

Description

Expected Result

1

Connect with Persistent Session

Connect with cleanSession=false

Session is maintained

2

Subscribe with Persistent Session

Subscribe to topic

Subscription is stored

3

Disconnect and Reconnect

Disconnect and reconnect

Subscription is restored

4

Publish During Disconnect

Publish while client is disconnected

Message is queued

5

Receive Queued Messages

Reconnect and receive queued messages

Messages are delivered

6

QoS 1 Message Queuing

Publish QoS 1 message during disconnect

Message is queued and delivered at least once

7

QoS 2 Message Queuing

Publish QoS 2 message during disconnect

Message is queued and delivered exactly once

8

QoS 0 Message During Disconnect

Publish QoS 0 message during disconnect

Message is discarded

9

Multiple Subscriptions

Subscribe to multiple topics

All subscriptions are retained

10

Session Expiry

Set session expiry interval

Session expires after timeout

11

Session Expiry Cancellation

Reconnect before expiry

Session remains active

12

Session with Retained Messages

Subscribe to topic with retained message

Retained message is delivered

13

Session with Will Message

Set LWT and disconnect unexpectedly

Will message is delivered

14

Session with Clean Start

Connect with clean start

Previous session is cleared

15

Session with Authentication

Connect with valid credentials

Session is maintained

16

Session with Invalid Credentials

Connect with invalid credentials

Connection denied

17

Session with TLS

Connect securely

Session is maintained

18

Session with Shared Subscription

Use shared subscription

Load-balanced messages retained

19

Session with Wildcard Subscription

Subscribe using wildcard

Subscription retained

20

Session with Topic Alias

Use topic alias

Alias retained across reconnect

21

Session with Message Expiry

Publish with expiry interval

Message expires if not delivered in time

22

Session with Offline Publisher

Publisher offline

Messages queued for subscribers

23

Session with Offline Subscriber

Subscriber offline

Messages queued

24

Session with Broker Restart

Restart broker

Session state is preserved

25

Session with Client Crash

Simulate client crash

Session is preserved

26

Session with Network Drop

Simulate network failure

Session is preserved

27

Session with Mobile Client

Use mobile client

Session is preserved across reconnects

28

Session with IoT Device

Use constrained device

Session is preserved

29

Session with Web Client

Use browser-based client

Session is preserved

30

Session with NAT

Client behind NAT

Session is preserved

31

Session with VPN

Client over VPN

Session is preserved

32

Session with IPv4

Use IPv4 connection

Session is preserved

33

Session with IPv6

Use IPv6 connection

Session is preserved

34

Session with Broker Cluster

Use clustered broker

Session state is synchronized

35

Session with Logging Enabled

Enable broker logging

Session events are logged

36

Session with Audit Trail

Review audit logs

Session activity is recorded

37

Session with Monitoring Tool

Monitor session state

Session status visible

38

Session with QoS Downgrade

Subscriber requests lower QoS

Messages delivered at requested QoS

39

Session with Duplicate Client ID

Connect with same client ID

Previous session ends, new session starts

40

Session with Message Ordering

Publish multiple messages

Messages delivered in order

41

Session with Message Delay

Delay message delivery

Messages delivered after reconnect

42

Session with Message Compression

Compress messages

Messages delivered correctly

43

Session with JSON Payload

Publish structured data

Payload delivered intact

44

Session with Binary Payload

Publish binary data

Payload delivered intact

45

Session with Large Payload

Publish large message

Message delivered if within limits

46

Session with Small Payload

Publish small message

Message delivered

47

Session with Will Delay Interval

Set will delay

Will message delayed

48

Session with Will Properties

Set custom properties

Properties delivered with message

49

Session with Clean Disconnect

Disconnect gracefully

Session remains active

50

Session with Broker Throttling

Broker under load

Session state preserved

Small Code Footprint - Testcases

#

Test Case

Description

Expected Result

1

Compile MQTT Client on Microcontroller

Build MQTT client on embedded board

Compilation succeeds

2

Connect from Embedded Device

Connect to broker from constrained device

Connection succeeds

3

Publish from Embedded Device

Publish message from microcontroller

Message is delivered

4

Subscribe from Embedded Device

Subscribe to topic from microcontroller

Messages are received

5

Use Minimal MQTT Library

Use lightweight MQTT library

Library fits within memory limits

6

Flash Size Check

Check firmware size with MQTT client

Size is within device limits

7

RAM Usage Check

Measure runtime memory usage

Memory usage is minimal

8

CPU Load Check

Measure CPU usage during MQTT operations

CPU usage is low

9

Power Consumption Test

Measure power usage during MQTT session

Power usage is minimal

10

Sleep Mode Compatibility

Enter sleep mode with MQTT client

Device wakes and reconnects

11

Wake on MQTT Event

Wake device on incoming MQTT message

Device wakes and processes message

12

Publish with QoS 0

Publish with minimal overhead

Message delivered best-effort

13

Subscribe with QoS 0

Subscribe with minimal overhead

Messages received best-effort

14

Use Static Memory Allocation

Avoid dynamic memory allocation

No memory fragmentation

15

Use MQTT-SN

Use MQTT for sensor networks

Protocol works with minimal stack

16

Use MQTT over UDP

Use MQTT-SN over UDP

Message delivered with low overhead

17

Use MQTT over Serial

Use MQTT over UART

Message delivered

18

Use MQTT over Bluetooth

Use MQTT over BLE

Message delivered

19

Use MQTT over LoRaWAN

Use MQTT with LoRa gateway

Message delivered

20

Use MQTT over NB-IoT

Use MQTT over narrowband IoT

Message delivered

21

Use MQTT on RTOS

Run MQTT client on real-time OS

Client operates correctly

22

Use MQTT on Bare Metal

Run MQTT client without OS

Client operates correctly

23

Use MQTT on FreeRTOS

Integrate MQTT with FreeRTOS

Client operates correctly

24

Use MQTT on Zephyr

Integrate MQTT with Zephyr OS

Client operates correctly

25

Use MQTT on TinyOS

Integrate MQTT with TinyOS

Client operates correctly

26

Use MQTT on RIOT OS

Integrate MQTT with RIOT OS

Client operates correctly

27

Use MQTT on Mbed OS

Integrate MQTT with Mbed OS

Client operates correctly

28

Use MQTT on ESP32

Run MQTT on ESP32

Client connects and communicates

29

Use MQTT on STM32

Run MQTT on STM32

Client connects and communicates

30

Use MQTT on Raspberry Pi Pico

Run MQTT on RP2040

Client connects and communicates

31

Use MQTT on Arduino

Run MQTT on Arduino board

Client connects and communicates

32

Use MQTT on NRF52

Run MQTT on Nordic chip

Client connects and communicates

33

Use MQTT on TI CC3200

Run MQTT on TI chip

Client connects and communicates

34

Use MQTT on Particle Photon

Run MQTT on Particle device

Client connects and communicates

35

Use MQTT on BeagleBone

Run MQTT on BeagleBone

Client connects and communicates

36

Use MQTT on Linux SBC

Run MQTT on single-board computer

Client connects and communicates

37

Use MQTT with Minimal Stack

Use MQTT with reduced stack size

Client operates correctly

38

Use MQTT with Minimal Heap

Use MQTT with reduced heap size

Client operates correctly

39

Use MQTT with Static Topics

Use fixed topic strings

Reduces memory usage

40

Use MQTT with Static Buffers

Use fixed-size buffers

Reduces memory fragmentation

41

Use MQTT with No TLS

Use plain MQTT for minimal footprint

Client connects and communicates

42

Use MQTT with Lightweight TLS

Use minimal TLS stack (e.g., mbedTLS)

Secure connection established

43

Use MQTT with Watchdog Timer

Integrate with watchdog

Client resets on failure

44

Use MQTT with OTA Updates

Update firmware over MQTT

Update succeeds

45

Use MQTT with Sensor Data

Publish sensor data

Message delivered

46

Use MQTT with Actuator Control

Receive control messages

Actuator responds

47

Use MQTT with Sleep Scheduling

Schedule sleep/wake cycles

MQTT session resumes

48

Use MQTT with Battery Monitoring

Monitor battery while using MQTT

Battery usage is efficient

49

Use MQTT with Event Triggering

Trigger events via MQTT

Events executed

50

Use MQTT with Minimal Dependencies

Build with no external libraries

Client compiles and runs

Bi-directional Communication - Testcases

#

Test Case

Description

Expected Result

1

Client Publishes to Broker

Client sends message to broker

Broker receives message

2

Broker Delivers to Subscriber

Broker sends message to subscribed client

Client receives message

3

Client Publishes and Subscribes

Same client publishes and subscribes

Client receives messages from broker

4

Multiple Clients Communicate

Clients publish and subscribe to each other

Messages exchanged via broker

5

Client Publishes to Topic A

Client A publishes to topic

Client B subscribed to topic receives message

6

Client Subscribes to Topic B

Client subscribes to topic

Receives messages from broker

7

Client Sends Command

Client sends control command

Target device receives and executes command

8

Device Sends Status Update

Device publishes status

Monitoring client receives update

9

Client Publishes JSON Payload

Send structured data

Subscriber receives and parses JSON

10

Client Publishes Binary Payload

Send binary data

Subscriber receives binary intact

11

Client Publishes with QoS 0

Send message with QoS 0

Message delivered best-effort

12

Client Publishes with QoS 1

Send message with QoS 1

Message delivered at least once

13

Client Publishes with QoS 2

Send message with QoS 2

Message delivered exactly once

14

Client Subscribes with QoS 0

Subscribe with QoS 0

Messages received best-effort

15

Client Subscribes with QoS 1

Subscribe with QoS 1

Messages received at least once

16

Client Subscribes with QoS 2

Subscribe with QoS 2

Messages received exactly once

17

Client Sends Command to IoT Device

Client publishes command

IoT device receives and acts

18

IoT Device Sends Sensor Data

Device publishes sensor reading

Client receives data

19

Client Publishes via Web App

Web client sends message

Subscriber receives message

20

Client Subscribes via Web App

Web client subscribes

Receives messages from broker

21

Client Publishes via Mobile App

Mobile client sends message

Subscriber receives message

22

Client Subscribes via Mobile App

Mobile client subscribes

Receives messages from broker

23

Client Publishes via CLI

Command-line client sends message

Subscriber receives message

24

Client Subscribes via CLI

Command-line client subscribes

Receives messages from broker

25

Client Publishes via Script

Script sends message

Subscriber receives message

26

Client Subscribes via Script

Script subscribes

Receives messages from broker

27

Client Publishes with TLS

Secure publish

Message encrypted and delivered

28

Client Subscribes with TLS

Secure subscribe

Message encrypted and received

29

Client Publishes with Authentication

Authenticated publish

Message accepted

30

Client Subscribes with Authentication

Authenticated subscribe

Subscription accepted

31

Client Publishes with Retain Flag

Publish retained message

New subscribers receive last message

32

Client Subscribes After Retain

Subscribe after retained message

Receives retained message

33

Client Publishes with Topic Alias

Use topic alias

Message routed correctly

34

Client Subscribes with Topic Alias

Receive message via alias

Message received

35

Client Publishes with Delay

Delay between messages

Messages still delivered

36

Client Subscribes with Delay

Delay between subscription and publish

Messages received if retained

37

Client Publishes with Expiry

Set message expiry

Message discarded after expiry

38

Client Subscribes After Expiry

Subscribe after expiry

Message not received

39

Client Publishes to Multiple Topics

Publish to multiple topics

Subscribers to each topic receive messages

40

Client Subscribes to Multiple Topics

Subscribe to multiple topics

Messages from all topics received

41

Client Publishes to Wildcard Topic

Publish to topic matching wildcard

Subscribers receive message

42

Client Subscribes with Wildcard

Subscribe using wildcard

Messages from matching topics received

43

Client Publishes with Will Message

Set LWT and disconnect

Will message delivered to subscribers

44

Client Subscribes to LWT Topic

Subscribe to LWT topic

Receives will message on disconnect

45

Client Publishes with Session

Persistent session publish

Messages queued if subscriber offline

46

Client Subscribes with Session

Persistent session subscribe

Messages received after reconnect

47

Client Publishes with Clean Session

Clean session publish

No messages retained

48

Client Subscribes with Clean Session

Clean session subscribe

No subscriptions retained

49

Client Publishes with Shared Topic

Publish to shared topic

Message delivered to one subscriber

50

Client Subscribes with Shared Topic

Subscribe to shared topic

Load-balanced message delivery

Security via TLS - Testcases

#

Test Case

Description

Expected Result

1

TLS Connection Establishment

Connect client with TLS enabled

Secure connection established

2

TLS Handshake Success

Perform TLS handshake

Handshake completes successfully

3

TLS Handshake Failure

Use invalid certificate

Connection fails

4

TLS with Valid Certificate

Use valid CA-signed certificate

Connection succeeds

5

TLS with Self-Signed Certificate

Use self-signed certificate

Connection may succeed with proper trust settings

6

TLS with Expired Certificate

Use expired certificate

Connection fails

7

TLS with Revoked Certificate

Use revoked certificate

Connection fails

8

TLS with Mismatched Hostname

Certificate hostname mismatch

Connection fails

9

TLS with Mutual Authentication

Use client and server certificates

Connection succeeds with mutual auth

10

TLS with Cipher Suite Negotiation

Negotiate cipher suite

Secure cipher selected

11

TLS with TLS 1.2

Use TLS version 1.2

Connection succeeds

12

TLS with TLS 1.3

Use TLS version 1.3

Connection succeeds

13

TLS with SSL

Use deprecated SSL version

Connection fails

14

TLS with Certificate Pinning

Pin server certificate

Connection succeeds only with pinned cert

15

TLS with CA Chain

Use full CA chain

Connection succeeds

16

TLS with Missing CA Chain

Omit CA chain

Connection fails

17

TLS with Encrypted Payload

Send encrypted message

Payload is encrypted

18

TLS with Large Payload

Send large encrypted message

Message delivered securely

19

TLS with Small Payload

Send small encrypted message

Message delivered securely

20

TLS with JSON Payload

Send structured data securely

JSON delivered securely

21

TLS with Binary Payload

Send binary data securely

Binary delivered securely

22

TLS with QoS 0

Publish with QoS 0 over TLS

Message delivered securely

23

TLS with QoS 1

Publish with QoS 1 over TLS

Message delivered securely

24

TLS with QoS 2

Publish with QoS 2 over TLS

Message delivered securely

25

TLS with Retained Message

Publish retained message over TLS

Message retained securely

26

TLS with Will Message

Configure LWT over TLS

Will message delivered securely

27

TLS with Topic Alias

Use topic alias over TLS

Alias resolved securely

28

TLS with Message Expiry

Set expiry over TLS

Message expires securely

29

TLS with Clean Session

Connect with clean session over TLS

Session cleared securely

30

TLS with Persistent Session

Connect with persistent session over TLS

Session maintained securely

31

TLS with Shared Subscription

Use shared subscription over TLS

Message delivered securely

32

TLS with Wildcard Subscription

Subscribe using wildcard over TLS

Messages received securely

33

TLS with Broker Restart

Restart broker with TLS enabled

Secure reconnection succeeds

34

TLS with Client Reconnect

Reconnect client with TLS

Secure session resumed

35

TLS with Network Drop

Simulate network failure

Secure reconnection succeeds

36

TLS with Mobile Client

Connect mobile client securely

TLS connection succeeds

37

TLS with IoT Device

Connect constrained device securely

TLS connection succeeds

38

TLS with Web Client

Connect browser-based client securely

TLS connection succeeds

39

TLS with VPN

Connect over VPN with TLS

Double encryption maintained

40

TLS with NAT

Connect behind NAT with TLS

TLS connection succeeds

41

TLS with IPv4

Connect using IPv4 with TLS

TLS connection succeeds

42

TLS with IPv6

Connect using IPv6 with TLS

TLS connection succeeds

43

TLS with Broker Cluster

Connect to clustered broker with TLS

Secure connection maintained

44

TLS with Logging Enabled

Enable TLS logging

Secure events logged

45

TLS with Audit Trail

Review audit logs

TLS activity recorded

46

TLS with Monitoring Tool

Monitor TLS traffic

Encrypted traffic visible

47

TLS with Performance Benchmark

Measure TLS overhead

Acceptable latency observed

48

TLS with Certificate Rotation

Rotate server certificate

Connection resumes securely

49

TLS with Certificate Renewal

Renew certificate

Connection resumes securely

50

TLS with Certificate Revocation Check

Enable revocation check

Revoked certs rejected

Extensible with MQTT5.0 - Testcases

#

Test Case

Description

Expected Result

1

Connect with MQTT 5.0

Connect using MQTT version 5.0

Connection succeeds

2

Connect with MQTT 3.1.1

Connect using older version

Connection succeeds with limited features

3

Publish with User Property

Add custom user property to publish message

Property is delivered to subscriber

4

Subscribe with User Property

Add user property to subscribe request

Property is acknowledged

5

Receive User Property

Receive message with user property

Property is visible to subscriber

6

Publish with Multiple User Properties

Add multiple user properties

All properties are delivered

7

Publish with Reason Code

Send message with reason code

Code is processed by broker

8

Connect with Reason Code

Connect and receive reason code

Code indicates success or failure

9

Disconnect with Reason Code

Disconnect with reason code

Broker logs reason

10

Subscribe with Reason Code

Subscribe and receive reason code

Code indicates subscription status

11

Enhanced Error Reporting

Trigger error and check reason string

Descriptive error message received

12

Invalid Topic Alias

Use invalid alias

Error reason code returned

13

Valid Topic Alias

Use valid alias

Message routed correctly

14

Topic Alias Mapping

Map alias to topic

Alias resolved

15

Topic Alias Reuse

Reuse alias for multiple messages

Messages routed correctly

16

Session Expiry Interval

Set session expiry

Session expires after interval

17

Message Expiry Interval

Set message expiry

Message discarded after expiry

18

Subscription Identifier

Use subscription identifier

Identifier is returned with messages

19

Flow Control

Use receive maximum

Broker limits message inflow

20

Maximum Packet Size

Set max packet size

Larger packets rejected

21

Request Response Information

Request broker response info

Info returned in CONNACK

22

Request Problem Information

Request detailed error info

Problem info returned

23

Server Disconnect

Broker disconnects client with reason

Client receives disconnect reason

24

Client Disconnect

Client disconnects with reason

Broker logs reason

25

Retain Available

Check if broker supports retained messages

Capability confirmed

26

Wildcard Subscription Available

Check wildcard support

Capability confirmed

27

Shared Subscription Available

Check shared subscription support

Capability confirmed

28

Subscription Options

Use no local, retain as published, etc.

Options applied

29

No Local Option

Use no local option

Client does not receive its own messages

30

Retain As Published Option

Use retain as published

Retain flag preserved

31

Retain Handling Option

Set retain handling

Retained messages handled accordingly

32

Assigned Client Identifier

Let broker assign client ID

ID returned in CONNACK

33

Server Keep Alive

Use server-defined keep-alive

Interval applied

34

Authentication Method

Use custom auth method

Auth exchange initiated

35

Authentication Data

Send auth data

Broker processes data

36

Enhanced Auth Exchange

Perform multi-step auth

Auth completes successfully

37

Reason String in CONNACK

Receive reason string on connect

String explains result

38

Reason String in PUBACK

Receive reason string on publish ack

String explains result

39

Reason String in SUBACK

Receive reason string on subscribe ack

String explains result

40

Reason String in DISCONNECT

Receive reason string on disconnect

String explains result

41

Connect with Clean Start

Use clean start flag

Session starts fresh

42

Connect with Session Expiry

Use session expiry with clean start

Session expires after interval

43

Publish with Payload Format Indicator

Set payload format (e.g., JSON)

Format indicated to subscriber

44

Publish with Content Type

Set content type (e.g., application/json)

Type visible to subscriber

45

Publish with Response Topic

Set response topic

Subscriber replies to specified topic

46

Publish with Correlation Data

Include correlation data

Data used to match responses

47

Subscribe with Subscription ID

Use subscription ID

ID included in messages

48

Broker Capability Advertisement

Broker advertises supported features

Client adapts behavior

49

Client Capability Declaration

Client declares limits (e.g., max packet size)

Broker respects limits

50

MQTT 5.0 Interoperability

Test with MQTT 3.1.1 client

Limited compatibility, no 5.0 features

  • Reference links