21  Introduction to IoT Protocols

Why IoT Needs Specialized Protocols and Stack Architecture

Key Concepts
  • Protocol: A set of rules governing how devices format, transmit, and interpret messages on a network
  • Protocol Stack: A vertical arrangement of protocols, each layer using services from the layer below and providing services to the layer above
  • IoT Protocol Landscape: The wide variety of protocols spanning physical, MAC, network, transport, and application layers used in IoT deployments
  • Constrained Device: A sensor or actuator with limited CPU, RAM, flash, and battery; constrains protocol choice to lightweight options
  • Interoperability Gap: The challenge that arises when devices using different protocols cannot communicate without a gateway or translator
  • Standard vs Proprietary Protocol: Standards-based protocols (Zigbee, LoRaWAN) allow multi-vendor ecosystems; proprietary protocols lock devices to one vendor
  • Protocol Selection Criteria: The set of requirements—power, range, data rate, cost, security—used to choose the right protocol for a deployment

21.1 In 60 Seconds

Traditional internet protocols (HTTP/TCP) assume abundant RAM, power, and bandwidth – resources IoT devices lack. A sensor with 32 KB RAM cannot run a full TCP/IP stack, so IoT uses specialized lightweight protocols at every layer: CoAP instead of HTTP, 6LoWPAN for IPv6 header compression, and 802.15.4 instead of Ethernet. Understanding these constraints and the IoT protocol stack is the foundation for all networking decisions.

Learning Objectives

By the end of this chapter, you will be able to:

  • Explain why traditional internet protocols are unsuitable for IoT devices
  • Identify the key constraints that drive IoT protocol design decisions
  • Describe each layer of the IoT protocol stack and its function
  • Map common IoT protocols to their respective layers
  • Select appropriate protocol stacks based on RFC 7228 device class constraints

21.2 Why IoT Needs Specialized Protocols

Traditional internet protocols like HTTP over TCP/IP were designed for desktop computers and servers with abundant resources. IoT devices operate under fundamentally different constraints that require specialized protocol designs.

21.2.1 The Resource Constraint Challenge

Comparison diagram showing traditional internet devices (desktop PC with 8GB RAM, server with 64GB RAM) using HTTP/TCP versus IoT devices (sensor node with 32KB RAM, constrained MCU with 10KB RAM) using lightweight protocols like CoAP and custom binary over LoRa
Figure 21.1: Resource comparison between traditional internet devices and IoT devices

Consider the dramatic differences between a web browser and a soil moisture sensor:

Resource Web Browser IoT Sensor Ratio
RAM 8 GB 32 KB 250,000×
CPU 3 GHz 16 MHz 187×
Storage 500 GB SSD 256 KB Flash 2,000,000×
Power 150W (continuous) 50 mW (intermittent) 3,000×
Network 1 Gbps Ethernet 250 kbps wireless 4,000×
Expected lifetime 3-5 years 10-15 years 3-5×
Unit cost target $500-2000 $1-20 25-2000×

Think about it this way: HTTP is like shipping a package in a big truck. The truck (HTTP header) is over 200 bytes, but your package (temperature reading) is only 4 bytes. You’re shipping 98% truck and 2% cargo!

HTTP overhead example:

GET /sensors/temp123/reading HTTP/1.1
Host: api.example.com
User-Agent: Mozilla/5.0
Accept: application/json
Connection: keep-alive
Content-Length: 4

25.5

That’s ~200 bytes of headers for a 4-byte temperature reading. On a 250 kbps wireless link, the headers alone take 6.4 milliseconds to transmit, consuming precious battery power.

CoAP equivalent:

[4 bytes header][4 bytes payload] = 8 bytes total

Same information, 25× smaller packet, 25× less energy to transmit!

21.2.2 RFC 7228: Constrained Node Classes

The IETF standardized device classification in RFC 7228 to help protocol designers understand target platforms:

Class Data (RAM) Code (Flash) Example Devices
Class 0 << 10 KB << 100 KB RFID tags, simple sensors
Class 1 ~10 KB ~100 KB 8-bit MCUs (ATmega328), low-end 32-bit (STM32L0)
Class 2 ~50 KB ~250 KB 32-bit MCUs (ESP32, nRF52840)
Full > 250 KB > 1 MB Raspberry Pi, smartphones

Design Implications:

  • Class 0: Too constrained for IP; use raw protocols or proprietary
  • Class 1: Minimal IP stack (6LoWPAN + CoAP); no TLS, limited features
  • Class 2: Full IP stack possible; can run MQTT, TLS with constraints
  • Full: Standard protocols work; focus on power optimization

21.2.3 Key IoT Protocol Requirements

IoT protocols must address these fundamental challenges:

  1. Minimal Overhead
    • Small header sizes (4 bytes vs 40+ bytes)
    • Efficient encoding (binary vs text)
    • Compressed addresses and identifiers
  2. Power Efficiency
    • Connectionless operation (no keep-alives)
    • Short transmissions (minimize radio-on time)
    • Sleep-friendly design (no polling)
  3. Unreliable Link Tolerance
    • Graceful degradation under packet loss
    • Simple retransmission mechanisms
    • No complex state machines
  4. Scalability
    • Support for millions of devices
    • Efficient addressing (IPv6)
    • Hierarchical network architectures

21.3 The IoT Protocol Stack

IoT systems use a layered protocol architecture similar to the traditional TCP/IP model, but with adaptations for constrained environments:

Layered IoT protocol stack diagram showing Application layer (CoAP, MQTT, HTTP, AMQP), Transport layer (UDP, TCP, DTLS, TLS), Network layer (IPv6, IPv4, RPL, 6LoWPAN), Data Link layer (802.15.4, BLE, Wi-Fi, LoRaWAN, NB-IoT), and Physical layer (2.4GHz, Sub-GHz, LTE bands)
Figure 21.2: IoT protocol stack layers with representative protocols

Note: 6LoWPAN is technically an adaptation layer between Network and Data Link, providing header compression and fragmentation.

21.3.1 Layer-by-Layer Protocol Mapping

Layer Traditional Internet IoT Protocols Key Difference
Application HTTP, SMTP, FTP CoAP, MQTT, AMQP Smaller headers, binary encoding
Transport TCP, TLS UDP, DTLS Connectionless for power saving
Network IPv4 IPv6, 6LoWPAN Compressed headers, larger address space
Data Link Ethernet, Wi-Fi 802.15.4, BLE, LoRa Low-power radio technologies
Physical Cat5/6, 802.11 Sub-GHz, 2.4 GHz Optimized for range/power trade-offs

21.3.2 Protocol Stack Interaction

Understanding how protocols interact across layers is essential for IoT system design:

Diagram of 6LoWPAN encapsulation header formats including basic compression, fragmentation, and mesh addressing, showing how 802.15.4 frames carry compressed IPv6 headers and payloads
Figure 21.3: 6LoWPAN encapsulation header formats showing compression options

Key Insight: Without 6LoWPAN compression, the IPv6 + UDP headers (48 bytes) consume nearly half the usable payload of an 802.15.4 frame (102 bytes), leaving only 50 bytes for CoAP and data. With IPHC compression, the headers shrink to as few as 10 bytes, dramatically improving efficiency.

Let’s quantify why 6LoWPAN compression is essential for 802.15.4 networks. Consider a sensor sending a 4-byte temperature reading:

Without 6LoWPAN compression: \[ \begin{aligned} \text{802.15.4 frame} &= 127\text{ bytes total} \\ \text{MAC header} &= 25\text{ bytes} \\ \text{Available payload} &= 127 - 25 = 102\text{ bytes} \\[0.5em] \text{IPv6 header} &= 40\text{ bytes} \\ \text{UDP header} &= 8\text{ bytes} \\ \text{CoAP header} &= 4\text{ bytes} \\ \text{Protocol overhead} &= 40 + 8 + 4 = 52\text{ bytes} \\[0.5em] \text{Remaining for data} &= 102 - 52 = 50\text{ bytes} \\ \text{Efficiency} &= \frac{4}{102} \times 100 = 3.9\% \end{aligned} \]

With 6LoWPAN compression: \[ \begin{aligned} \text{IPv6 compressed} &= 6\text{ bytes (85\% reduction)} \\ \text{UDP compressed} &= 4\text{ bytes} \\ \text{CoAP header} &= 4\text{ bytes} \\ \text{Protocol overhead} &= 6 + 4 + 4 = 14\text{ bytes} \\[0.5em] \text{Remaining for data} &= 102 - 14 = 88\text{ bytes} \\ \text{Frame efficiency} &= \frac{4}{102} \times 100 = 3.9\% \text{ (payload vs frame)} \\ \text{Stack efficiency} &= \frac{4}{4 + 14} \times 100 = 22.2\% \text{ (payload vs protocol+payload)} \end{aligned} \]

Impact on battery life (1000 readings, 30 mA TX current, 250 kbps): \[ \begin{aligned} \text{Without compression:} \\ \text{TX time per packet} &= \frac{56 \times 8}{250{,}000} = 1.792\text{ ms} \\ \text{Charge} &= 1000 \times 0.001792\text{ s} \times 30\text{ mA} = 53.8\text{ mAs} = 0.0149\text{ mAh} \\[0.5em] \text{With compression:} \\ \text{TX time per packet} &= \frac{18 \times 8}{250{,}000} = 0.576\text{ ms} \\ \text{Charge} &= 1000 \times 0.000576\text{ s} \times 30\text{ mA} = 17.3\text{ mAs} = 0.0048\text{ mAh} \\[0.5em] \text{Energy savings} &= \frac{53.8 - 17.3}{53.8} \times 100 \approx 68\% \end{aligned} \]

Result: 6LoWPAN compression saves 68% TX energy per reading and enables 3.1x more payload space (88 vs 50 bytes) – essential for battery-powered 802.15.4 IoT deployments. In practice, total energy savings are even larger because radio receive, idle listening, and protocol retransmissions also decrease with smaller packets.

Try It: 6LoWPAN Compression Efficiency Calculator

Explore how payload size and compression affect protocol efficiency on 802.15.4 networks.

21.4 Common IoT Protocol Stacks

Different deployment scenarios call for different protocol combinations. Here are the most common IoT protocol stacks:

21.4.1 Stack 1: Constrained Sensor Network (802.15.4)

Use Case: Indoor sensor mesh (temperature, humidity, occupancy)

┌─────────────────────────────────────┐
│ Application: CoAP (4 bytes)         │
├─────────────────────────────────────┤
│ Transport: UDP (8 bytes)            │
├─────────────────────────────────────┤
│ Network: IPv6 (40→6 bytes via       │
│         6LoWPAN compression)        │
├─────────────────────────────────────┤
│ Adaptation: 6LoWPAN                 │
├─────────────────────────────────────┤
│ Data Link: IEEE 802.15.4            │
│ (25 bytes MAC header)               │
├─────────────────────────────────────┤
│ Physical: 2.4 GHz, 250 kbps         │
└─────────────────────────────────────┘

Total overhead: ~39 bytes (with compression)
Payload efficiency: ~10% for 4-byte readings

21.4.2 Stack 2: Wi-Fi Connected Device

Use Case: Smart home device (thermostat, camera)

┌─────────────────────────────────────┐
│ Application: MQTT (2-4 bytes)       │
├─────────────────────────────────────┤
│ Transport: TCP (20 bytes)           │
│            + TLS (5-40 bytes)       │
├─────────────────────────────────────┤
│ Network: IPv4 (20 bytes)            │
│          or IPv6 (40 bytes)         │
├─────────────────────────────────────┤
│ Data Link: IEEE 802.11 (Wi-Fi)      │
│ (34 bytes MAC header)               │
├─────────────────────────────────────┤
│ Physical: 2.4/5 GHz, 54-600 Mbps    │
└─────────────────────────────────────┘

Total overhead: ~80-140 bytes
Best for: mains-powered, high-bandwidth

21.4.3 Stack 3: LPWAN Remote Sensor

Use Case: Agricultural monitoring, asset tracking

┌─────────────────────────────────────┐
│ Application: Custom binary or CoAP  │
├─────────────────────────────────────┤
│ (No IP layer - LoRaWAN provides     │
│  addressing and security)           │
├─────────────────────────────────────┤
│ Data Link: LoRaWAN MAC (13 bytes)   │
├─────────────────────────────────────┤
│ Physical: Sub-GHz (868/915 MHz)     │
│           0.3-50 kbps               │
└─────────────────────────────────────┘

Total overhead: ~13 bytes
Range: 2-15 km
Battery life: 5-15 years
Try It: Protocol Stack Overhead Comparison

Compare the total overhead of different IoT protocol stacks for a given payload.

21.5 Protocol Categories by Function

IoT protocols can be grouped by their primary function in the communication system:

21.5.1 Communication Pattern Protocols

Pattern Protocol Description Best For
Request-Response CoAP, HTTP Client requests, server responds Device configuration, data retrieval
Publish-Subscribe MQTT, AMQP Publishers send to topics, subscribers receive Telemetry, event-driven systems
Push Notifications WebSocket, CoAP Observe Server pushes updates to clients Real-time alerts, dashboards

21.5.2 Transport Protocols

Protocol Connection Reliability Overhead Power Security
UDP Connectionless Best-effort 8 bytes Low None (add DTLS)
TCP Connection-oriented Guaranteed 20+ bytes High None (add TLS)
QUIC Connection-oriented Guaranteed Variable Medium Built-in

21.5.3 Network Protocols

Protocol Addresses Header Size Compression IoT Suitability
IPv4 4.3 billion 20 bytes No Limited (NAT required)
IPv6 340 undecillion 40 bytes Via 6LoWPAN Excellent
6LoWPAN IPv6 (compressed) 2-6 bytes Yes Essential for 802.15.4

21.6 Deployment Scenarios

The three protocol stacks above map to real-world deployment patterns. Understanding where each fits helps in system design:

Three IoT deployment scenarios: Smart Home using Zigbee sensors with 6LoWPAN to hub with MQTT to cloud, Smart Agriculture using LoRa sensors to gateway to MQTT server, and Fleet Tracking using NB-IoT GPS trackers through cellular to cloud API
Figure 21.4: IoT deployment scenarios showing protocol selection by use case
  • Smart Home (Stack 1 + Stack 2): Zigbee/802.15.4 sensors use CoAP/6LoWPAN to communicate with a hub, which bridges to MQTT/Wi-Fi for cloud connectivity.
  • Smart Agriculture (Stack 3): LoRaWAN sensors send small payloads over long range to a gateway, which forwards data to an MQTT server.
  • Fleet Tracking (cellular): NB-IoT or LTE-M GPS trackers use cellular connectivity for wide-area, always-on communication.

21.7 Common IoT Acronyms Reference

Acronym Full Name Layer Purpose
6LoWPAN IPv6 over Low-power WPAN Adaptation IPv6 header compression
AMQP Advanced Message Queuing Protocol Application Enterprise messaging
CoAP Constrained Application Protocol Application RESTful for constrained devices
DTLS Datagram Transport Layer Security Transport Secure UDP
HTTP Hypertext Transfer Protocol Application Web protocol
ICMPv6 Internet Control Message Protocol v6 Network Network diagnostics
IPv6 Internet Protocol version 6 Network 128-bit addressing
LLN Low-Power and Lossy Network - Constrained network type
LoRaWAN Long Range WAN Data Link LPWAN protocol
LPWAN Low-Power Wide Area Network - Network category
MQTT Message Queue Telemetry Transport Application Pub/sub messaging
NB-IoT Narrowband IoT Data Link Cellular LPWAN
RPL IPv6 Routing Protocol for LLN Network IoT routing
TLS Transport Layer Security Transport Secure TCP
UDP User Datagram Protocol Transport Connectionless transport
WPAN Wireless Personal Area Network - Network category

RFC 7228 defines constrained device classes, but choosing the right protocol stack for each class isn’t obvious. Use this framework:

Device Class RAM Code Recommended Stack Avoid Example Devices
Class 0 <10 KB <100 KB Proprietary binary over LoRa/Zigbee MAC
No IP stack fits
TCP/IP, TLS, JSON RFID tags, simple beacons, wake-on-radio sensors
Class 1 ~10 KB ~100 KB CoAP/DTLS + UDP + 6LoWPAN + 802.15.4
Full TLS stack won’t fit, use DTLS
HTTP, MQTT, Full TLS, XML ATmega328 (Arduino Uno), STM32L0, basic Zigbee nodes
Class 2 ~50 KB ~250 KB MQTT/TLS + TCP + IPv6 + Wi-Fi OR
CoAP/DTLS + UDP + 6LoWPAN
AMQP, XMPP ESP32, nRF52840, Thread border routers
Full >250 KB >1 MB Any protocol — focus on power optimization None — only power matters Raspberry Pi, smartphones, gateways

Key Selection Questions:

1. Can your device even parse the protocol?

Memory requirement estimates (code + runtime):
- Raw binary: 2-5 KB
- CoAP: 10-15 KB (uCoAP library)
- MQTT: 20-30 KB (PahoMQTT library)
- HTTP: 40-60 KB (libcurl)
- TLS: 60-100 KB (mbedTLS)

2. Does your network layer support the protocol?

802.15.4 (127-byte frames):
  ✅ CoAP (4-byte header + 6LoWPAN compression)
  ❌ HTTP (200+ byte headers exceed frame size entirely)

Wi-Fi (1500-byte MTU):
  ✅ All protocols (no fragmentation needed)

3. Does power budget allow TCP connection overhead?

MQTT over TCP:
  - CONNECT + CONNACK: 2 packets before any data
  - PINGREQ/PINGRESP: Every 60s (keep-alive)
  - Total: ~140 bytes overhead per minute even with zero data

CoAP over UDP:
  - Connectionless: Send data immediately
  - Total: 0 bytes overhead if no data to send

Real Decision Example:

Soil Moisture Sensor (ATmega328P, 2 KB SRAM, 32 KB Flash, 802.15.4 radio):

  • Borderline Class 0/Class 1 device → Stack must fit in 2 KB RAM
  • Sends 4 bytes every 5 minutes
  • Battery-powered (3 years target)

Stack Evaluation:

Stack RAM Use Energy/Day Battery Life Verdict
HTTP/TCP 1.8 KB 45 mAh 67 days ❌ Doesn’t fit
MQTT/TCP 1.2 KB 32 mAh 94 days ⚠️ Fits but heavy
CoAP/UDP 0.6 KB 8 mAh 375 days Optimal

Decision: CoAP over UDP with 6LoWPAN compression.

Why:

  • Fits comfortably in RAM (0.6 KB < 2 KB)
  • Minimizes energy (8 mAh vs 32-45 mAh)
  • Meets battery target (375 days > 365 days)

Anti-Pattern to Avoid: “Let’s use MQTT because it’s popular.” Popularity doesn’t mean it fits your constraints.

Quick Decision Tree:

START → Is device Class 0?
        ├─ YES → Use proprietary binary or application-layer only
        └─ NO → Does it have <20 KB RAM (Class 1)?
                ├─ YES → Use CoAP/UDP/6LoWPAN
                └─ NO → Does it have <100 KB RAM (Class 2)?
                        ├─ YES → Use MQTT/TCP OR CoAP/UDP
                        └─ NO → Use any protocol, optimize for power

Common Pitfalls

LoRaWAN and Zigbee both call themselves “IoT protocols” but serve completely different use cases (wide-area vs short-range mesh). Fix: categorise protocols by range, data rate, and power before comparing them.

Datasheets list ideal-condition specifications. Real-world RF performance in concrete buildings or industrial environments differs significantly. Fix: run a small pilot with real hardware before committing to a protocol for a large deployment.

Zigbee 2012 and Zigbee 3.0 devices may not interoperate despite sharing the “Zigbee” brand name. Fix: verify exact protocol version and profile compatibility between all devices in a deployment.

A protocol with one vendor and no active community may be discontinued, leaving devices unsupported. Fix: prefer protocols with multiple certified implementations and an active standards body.

21.8 Summary

IoT protocols are specifically designed for resource-constrained devices and lossy networks:

Key Takeaways

Why IoT-Specific Protocols:

  • Traditional protocols (HTTP, IPv4) designed for desktop computers with GB of RAM
  • IoT devices have KB of RAM, MHz CPUs, and battery constraints
  • Need: Lightweight, power-efficient protocols with small overhead

Protocol Stack Layers:

  • Application: CoAP (RESTful), MQTT (pub-sub), AMQP (queuing)
  • Transport: UDP (connectionless, low power), TCP (reliable, higher power)
  • Network: IPv6 with 6LoWPAN compression for constrained networks
  • Data Link: 802.15.4, BLE, LoRaWAN, Wi-Fi depending on range/power needs

Device Classification (RFC 7228):

  • Class 0 (<<10 KB RAM, <<100 KB Flash): Too constrained for IP, use raw protocols
  • Class 1 (~10 KB RAM, ~100 KB Flash): Minimal IP stack, CoAP/UDP/6LoWPAN
  • Class 2 (~50 KB RAM, ~250 KB Flash): Full IP stack possible, can run MQTT/TLS
  • Full (>250 KB RAM, >1 MB Flash): Standard protocols, focus on optimization

Protocols are like special languages that help IoT devices talk to each other!

21.8.1 The Sensor Squad Adventure: The Great Message Relay Race

One day, Signal Sam the Communication Expert had an important message to deliver: “The garden is too dry - please turn on the sprinklers!” The message came from Thermo the Temperature Sensor and Sunny the Light Sensor in the backyard.

But here’s the problem - Signal Sam couldn’t just shout the message! The message had to travel through the air, across the neighborhood, through the internet, and all the way to the cloud computer. That’s like trying to talk to someone on the other side of the world!

“Don’t worry,” said Signal Sam. “I know special languages called PROTOCOLS that help me talk to different helpers along the way!”

First, Signal Sam used Zigbee language to talk to the nearby router (like whispering to your neighbor). Then the router used Wi-Fi language to talk to the home gateway (like talking normally in your house). Finally, the gateway used Internet language to send the message to the cloud (like mailing a letter to someone far away).

Power Pete the Battery Manager was watching carefully. “Great job, Signal Sam! You used the smallest, lightest messages possible so you didn’t waste my battery energy. That’s why we use special IoT protocols instead of regular computer messages - they’re designed to save power!”

The cloud computer got the message and told the sprinklers to turn on. Mission accomplished!

21.8.2 Key Words for Kids

Word What It Means
Protocol A special language that devices use to talk to each other - like how you might speak English to friends and Spanish to grandma!
Wi-Fi An invisible signal that carries messages through the air in your house, like magic mail floating around
The Cloud Really big computers far away that store information and help your devices work together, like a super-smart helper in the sky
Packet A tiny digital envelope that carries your message from one place to another

21.8.3 Try This at Home!

Play the Telephone Game with Rules! This shows how protocols work.

  1. Get 4-5 family members to stand in a line
  2. The first person whispers a message to the second person
  3. But here’s the protocol (rule): Each person must say “Message received!” before passing it on
  4. See if the message arrives correctly at the end!

What you learned: The “Message received!” rule is like a protocol - it makes sure each person got the message correctly before passing it on. IoT devices use similar rules to make sure messages don’t get lost!

Bonus Challenge: Try the game without the “Message received!” rule. Does the message get mixed up more often? That’s why protocols matter!

21.9 Concept Relationships

Understanding how IoT protocol introduction concepts interconnect:

  • Resource constraints (KB RAM, MHz CPU, mW power) directly determine protocol requirements (minimal overhead, power efficiency, unreliable link tolerance)
  • Device classes (RFC 7228 Class 0/1/2/Full) map to protocol stack capabilities — Class 1 can run CoAP/UDP/6LoWPAN, Class 0 cannot run IP at all
  • Protocol overhead compounds across layers: 4-byte CoAP + 8-byte UDP + 40-byte IPv6 = 52 bytes (before 6LoWPAN compression)
  • Communication patterns (request-response, publish-subscribe, push notifications) determine application protocol selection — CoAP for one-to-one, MQTT for one-to-many
  • Deployment scenarios (constrained sensor network, Wi-Fi connected, LPWAN remote) each require different protocol stack combinations

21.10 What’s Next?

Direction Chapter Description
Next IoT Protocols: Stack Architecture Layer-by-layer protocol breakdown
Previous IoT Protocols Fundamentals Protocol stack overview and roadmap
Hands-On IoT Protocols: Labs and Selection Practical protocol implementation

Further Reading: