Home of RF and Wireless Vendors and Resources

One Stop For Your RF and Wireless Need

MQTT Tutorial | MQTT architecture,working operation,use cases

This MQTT tutorial covers MQTT architecture, MQTT working operation and MQTT use cases including message flow. It mentions link to difference between MQTT, REST and HTTP. It is used in IoT wireless technologies such as zigbee, LoRaWAN etc.

MQTT broker based architecture

The figure-1 depicts MQTT architecture. As mentioned MQTT is broker based protocol. In this end devices (i.e. clients) communicate via broker. The broker is a server which can be installed on any machine in the cloud. There are different types of brokers such as HiveMQ, Mosquitto etc. The single client and broker can also communicate with each other.

Following table mentions MQTT messages used between client and Broker. As MQTT runs above TCP/IP layer, it is also connection oriented protocol. The client establishes connection with the broker (i.e. server) before the communication. MQTT is a publish-subscribe protocol. Here both client and server publish about any information (i.e. parameter such as temperature, humidity, event (ON/OFF) etc.) to each other using "PUBLISH" message. Any number of clients or end devices can subscribe for event with the broker. Due to this subscription, when there is a change in any event or parameter, broker will intimate to the subscribed clients about the change in event or parameter (i.e. temperature, humidity etc.).

MQTT message Description with direction of flow
CONNECT client to server (i.e. broker), client requests to connect with server.
CONNACK server to client, connect acknowledgment
PUBLISH client to server OR server to client
Publish message
PUBACK client to server OR server to client
Publish acknowledgment
PUBREC client to server OR server to client
Publish received
PUBREL client to server OR server to client
Publish release
PUBCOMP client to server OR server to client
Publish complete
SUBSCRIBE Client to server
client subscribe request
SUBACK Server to client
Subscribe acknowledgment
UNSUBSCRIBE client to server
unsubscribe request
UNSUBACK server to client
unsubscribe acknowledgment
PINGREQ client to server
Ping request
PINGRESP server to client
DISCONNECT client to server , client is disconnecting

MQTT protocol message format

The figure-2 depicts MQTT message format. It consists of fixed message header, variable header and payload. The first two bytes are used by most of the message types. Few of the message types use variable header and payload.

MQTT Working Operation | MQTT Use Cases

MQTT message flow

Let us understand working operation of MQTT protocol. The figure-3 depicts MQTT message flow between client and broker. We will take two use cases to understand the same.

Use Case#1: Broker wants to switch ON or OFF the light connected with remote client#1
➨Initially connection is established by client#1 with broker using CONNECT and CONNACK messages.
➨Next Broker communicate with Client#1 to switch ON or OFF the light interfaced with it. The messages such as PUBLISH and PUBREC are used for it.
This use case is used to switch ON/OFF the street lights in zigbee or LoRaWAN network. The lights are usually connected with end nodes or end devices in these wireless networks. The single Zigbee or LoRaWAN gateway controls multiple end nodes. Multiple such gateways are needed to cover entire city.

Use Case#2: Client#2 or client#3 wants to update temperature/humidity status to the broker based on sensors
➨Client#2 and Client#3 will intimate temperature or humidity update to the broker using PUBLISH message. This information is stored in the database and will be sent to all the subscribers who have subscribed for these topics (i.e. temperature, humidity). These informations is "pushed" to all the subscribed clients of the topics.
➨If client#1 has already subscribed for subscription to topics (i.e. temperature, humidity), it will get the information from broker using PUSH operation.
This use case is used for obtaining different types of sensing information automatically whenever there is any updates. For this purpose, different types of sensors (such as humidity sensor, temperature sensor etc.) are interfaced with end nodes. These end nodes publish informations (of any event updates) to the broker. The broker intimates changes to all the subscribed clients. The communication between gateway

Difference between MQTT vs HTTP, MQTT vs DDS, MQTT vs REST, MQTT vs SMQTT

MQTT vs HTTP >>   MQTT vs REST >>   MQTT vs DDS >>   MQTT vs SMQTT >>

Zigbee and LoRaWAN Related Links

Main page LoRa tutorial
LoRa Frequency Bands
LoRa protocol stack
LoRa MAC layer
LoRaWAN classes
LoRa features
LoRa Transceiver module
what is zigbee
Zigbee network architecture basics
Zigbee Protocol Stack
Zigbee Physical layers
Zigbee physical layer frame
Zigbee MAC layer frames
Zigbee frequency bands
Zigbee Gadgets
Zigbee Products

IoT Wireless Technologies

WLAN    ➤THREAD    ➤EnOcean    ➤LoRa    ➤SIGFOX    ➤WHDI   
Zigbee   ➤6LoWPAN   ➤Zigbee RF4CE   ➤Z-Wave   ➤NFC   ➤RFID   ➤INSTEON  

What is difference between

Difference between OSI and TCPIP layers
Difference between TCP UDP
IPV4 vs IPV6
Difference between Internet and Intranet

RF Wireless Tutorials

Share this page

Translate this page