Embedded Systems Learning Path Part 88 of 129 — View Full Path →
KEY TAKEAWAYS
MQTT is a lightweight publish-subscribe protocol ideal for constrained IoT devices
CoAP is a RESTful protocol designed for low-power, lossy networks with UDP transport
HTTP is widely supported but has higher overhead, making it less suitable for constrained devices
Choose MQTT for real-time messaging, CoAP for resource-constrained RESTful access, HTTP for cloud integration
Why IoT Needs Special Protocols
When your embedded device connects to the internet, it needs to exchange data with servers, cloud platforms, or other devices. While you could use plain HTTP (like a web browser), IoT devices have constraints that make specialized protocols more suitable:
Limited bandwidth: Wireless links may be slow (LoRa, NB-IoT)
Limited power: Every byte transmitted costs battery life
Unreliable connections: Devices go offline, networks are lossy
Many devices: A server may handle thousands of simultaneous connections
The three most common IoT application protocols are MQTT, CoAP, and HTTP.
HTTP (HyperText Transfer Protocol)
HTTP is the protocol that powers the web. It follows a simple request-response model: the client sends a request, the server sends a response.
How HTTP Works
Figure: HTTP request-response: a GET is answered with 200 OK and the data; a POST that creates a record is answered with 201 Created.
HTTP for IoT: Pros and Cons
Pros:
Universal: every cloud platform supports it
Simple to understand and implement
REST APIs are well documented
Works with any WiFi-capable device
Cons:
Verbose headers add overhead (hundreds of bytes per request)
Request-response only: server cannot push data to the device
Each request opens a new connection (or uses keep-alive)
Not suitable for constrained networks (LoRa, NB-IoT)
Best for: WiFi-connected devices that occasionally send data to REST APIs or cloud services.
MQTT (Message Queuing Telemetry Transport)
MQTT is the most popular IoT protocol. It was designed specifically for constrained devices and unreliable networks. It uses a publish-subscribe pattern with a central broker.
How MQTT Works
Figure: MQTT publish-subscribe: the sensor publishes to the broker, and the broker forwards the message to every subscriber of the topic.
Broker forwards it to ALL subscribers of “home/temperature”
Devices publish messages to a topic (a string like “home/living-room/temperature”). Other devices subscribe to topics they are interested in. The broker handles routing messages from publishers to subscribers.
MQTT Topics
Topics are hierarchical strings separated by forward slashes:
home/+/temperature – matches temperature in any room
home/# – matches everything under home/
MQTT Quality of Service (QoS)
QoS Level
Guarantee
Use Case
QoS 0
At most once (fire and forget)
Non-critical sensor data
QoS 1
At least once (may duplicate)
Important data, duplicates are OK
QoS 2
Exactly once (no loss, no duplicates)
Critical commands (payment, control)
MQTT Features for IoT
Last Will and Testament (LWT): When a device connects, it registers a “last will” message. If the device disconnects unexpectedly, the broker publishes this message automatically. Other devices can detect the offline status.Retained Messages: The broker stores the last message on a topic. When a new subscriber connects, it immediately receives the latest value without waiting for the next publish.Persistent Sessions: If a device goes offline, the broker queues messages. When the device reconnects, it receives the missed messages.
CoAP is designed for very constrained devices and networks. It is like a lightweight version of HTTP but uses UDP instead of TCP, making it much lighter.
How CoAP Works
CoAP follows a request-response model similar to HTTP but with much smaller packets:Figure: CoAP request-response: a GET with a 4-byte header plus options gets a tiny 2.05 Content response.
CoAP also supports an observe pattern: a client subscribes to a resource, and the server pushes updates automatically when the value changes (similar to MQTT subscribe but without a broker).
CoAP Characteristics
Feature
Detail
Transport
UDP (port 5683), DTLS for security
Overhead
4-byte fixed header (very minimal)
Pattern
Request-Response + Observe
Broker
Not required (direct device-to-device)
Discovery
Built-in resource discovery
Use CoAP when: Devices are extremely constrained (8-bit MCUs, very limited RAM), networks are lossy (6LoWPAN, NB-IoT), or you need a RESTful interface without the weight of HTTP.
MQTT vs CoAP vs HTTP Comparison
Feature
HTTP
MQTT
CoAP
Transport
TCP
TCP
UDP
Header Size
Large (~700 bytes)
Small (2 bytes)
Tiny (4 bytes)
Pattern
Request-Response
Publish-Subscribe
Request-Response + Observe
Server Push
No (polling only)
Yes (subscribe)
Yes (observe)
Broker Needed
No
Yes
No
Power Efficiency
Low
Medium-High
High
Reliability
TCP guarantees
QoS levels 0/1/2
Confirmable messages
Best For
REST APIs, cloud
IoT messaging, telemetry
Constrained devices
How to Choose
Use HTTP when:
Your device has WiFi and ample resources (ESP32, Raspberry Pi)
You are integrating with existing REST APIs
Data is sent infrequently (once per minute or less)
Use MQTT when:
You need real-time bidirectional communication
Multiple devices need to receive the same data
You want reliable delivery with QoS guarantees
Cloud platforms like AWS IoT, Azure IoT, or Google Cloud IoT are involved
Use CoAP when:
Devices are extremely resource-constrained
Network bandwidth is very limited (6LoWPAN, NB-IoT)
You want a RESTful model without HTTP overhead
Direct device-to-device communication without a broker
Summary
HTTP, MQTT, and CoAP each serve different needs in the IoT ecosystem. HTTP is universal but heavy. MQTT is the sweet spot for most IoT projects with its efficient publish-subscribe model and excellent cloud platform support. CoAP is the lightest option for the most constrained devices and networks. Many real-world IoT systems use a combination: MQTT between devices and broker, HTTP between the broker and web dashboards, and CoAP on the most constrained edge nodes.
Vivek Bhageria — Lead Firmware R&D Engineer, 12+ years. Ex-Bosch (automotive powertrain), MusicTribe (real-time audio), medical devices. M.Tech BITS Pilani. I write at NerdyElectronics — practical, register-level embedded systems for engineers who want to understand what’s actually happening under the hood.