IoT 6 - MQTT

2 min read

IoT 6 - MQTT

MQTT is a lightweight, publish–subscribe, machine-to-machine network protocol for message queuing

MQTT is a lightweight, publish–subscribe, machine-to-machine network protocol for message queuing. There are 4 components: Publisher, Subscriber, Topics (in the explorer), and Broker, which accept and filter the data.

The objective of this project is to publish the data to the public MQTT broker and analyze the data packet structure, which includes the Header & Payload, using Wireshark software.


1. First, prepare for the installation of the software

Article screenshot: iot 6 1

Installing MQTT Explorer in App Store.

Article screenshot: iot 6 2

Installing Wireshark on their official website.

For macOS, don’t forget to install ChmodBPF so that Wireshark is able to detect the network interface.


2. Open the MQTT Explorer, and modify the default connection.

Article screenshot: iot 6 3

Click “Advanced”, delete the default subscription, and add a new one using your identity or something else. Press “Back” and then connect it.

Article screenshot: iot 6 4


3. Write the topic and the value all you want (either in raw, XML, or JSON), then publish it.

Article screenshot: iot 6 5


4. Open Wireshark. Click twice on the “Wi-Fi: en0”.

Article screenshot: iot 6 6

This interface will pop up. Use the filter function on the top, and write “mqtt”. You will see that there is no result coming out unless you publish your topic in the MQTT Explorer before.

Article screenshot: iot 6 7

This is what happens when you have already published your topic.

Article screenshot: iot 6 8


5. Analyze the total length in Wireshark

a. Total Packet

Open “Frame”, then you will see the information about the packet length. It says 115 bytes.

Article screenshot: iot 6 9

b. Ethernet Header

Click “Ethernet II”. See what happens in the hex view. It indicates that the ethernet header’s length consists of 14 bytes.

Article screenshot: iot 6 10

c. IP Header

Open “Internet Protocol Version 4”, and you will see the IP header length is 20 bytes.

Article screenshot: iot 6 11

d. TCP Header

Open “Transmission Control Protocol”, it says that the header length is 32 bytes.

Article screenshot: iot 6 12

e. MQTT (header + payload)

Total MQTT payload is the total bytes of the topic’s value; in this case, it is 24 bytes.

Article screenshot: iot 6 13

Article screenshot: iot 6 14

Now, we know that:

payload length = 24 bytes
msg length = variable length + payload = 47 bytes
variable length = msg length − payload = 47 − 24 = 23 bytes
fixed length = 2 bytes
header length = variable length + fixed length = 23 + 2 = 25 bytes
MQTT total = 24 + 23 + 2 = 49 bytes

So, we can conclude that:

Article screenshot: iot 6 15