Pradeep Singh | 21st April 2016
You can get a better understanding of MQTT Protocol by capturing the MQTT Packets on your machine and analysing the pattern of communication between Client and Broker. To do this all you need is Wireshark Application (Download Link). Once you have Wireshark installed on your machine simply select the Network Interface and start capturing the traffic.
You can also go through following video to get quick idea about MQTT Traffic capture and analysis –
Download Links for Python Scripts and Captured Traffic –
Some Good To Know Points –
1. The MQTT protocol is based on TCP/IP and both client and broker need to have a TCP/IP stack.
2. Both Publisher and Subscriber are considered as MQTT Client.
3. The MQTT connection is always established between a client and the broker, no client is connected to another client directly.
4. Once the connection is established, the broker will keep it open as long as the client doesn’t send a disconnect command or it looses the connection.
5. MQTT Supports devices behind a NAT Device (For Ex- Router or Firewall).
6. The client identifier (short ClientId) is an identifier of each MQTT client connecting to a MQTT broker.
7. The Keep Alive is a time interval, the clients commits to by sending regular PING Request messages to the broker. The broker responds back with PING Response and this mechanism will allow both sides to determine if the other one is still alive and reachable.
8. The connection is initiated through a client sending a “Connect Command” message to the broker. The broker responds back with a “Connect Ack” and a status code. In the following table you can see all return codes at a glance.
|Return Code||Return Code Response|
|1||Connection Refused, unacceptable protocol version|
|2||Connection Refused, identifier rejected|
|3||Connection Refused, Server unavailable|
|4||Connection Refused, bad user name or password|
|5||Connection Refused, not authorized|
9. To see all the other low level details about MQTT you can refer to MQTT Specifications Page.