660 Protocol Overhead Analysis
Battery Life Calculations and Hands-On Labs
By the end of this chapter, you will be able to:
- Calculate protocol overhead for different IoT stacks
- Analyze battery life impact of protocol selection
- Understand the efficiency gains from 6LoWPAN compression
- Perform hands-on analysis using ESP32 simulators
- Compare protocol efficiency through practical calculations
660.1 Hands-On Lab: Protocol Overhead Analysis
Understanding protocol overhead is essential for designing efficient IoT systems. This section provides hands-on exercises to calculate and compare overhead across different protocol stacks.
660.1.1 Lab Activity: Compare Protocol Efficiency
Objective: Calculate and compare overhead for different protocol combinations
Scenario: Temperature sensor (2 bytes) and humidity (2 bytes) = 4 bytes payload
660.1.2 Task 1: Calculate Total Frame Size
Calculate frame size for different protocol stacks:
- Full stack (uncompressed): 802.15.4 + IPv6 + UDP + CoAP
- Compressed stack: 802.15.4 + 6LoWPAN + UDP + CoAP
- MQTT stack: Ethernet + IPv6 + TCP + MQTT
- HTTP stack (for comparison): Ethernet + IPv4 + TCP + HTTP
Click to see solution
1. Full Stack (Uncompressed):
802.15.4 MAC: 25 bytes
IPv6: 40 bytes
UDP: 8 bytes
CoAP: 4 bytes
Payload: 4 bytes
Total: 81 bytes
Overhead: 77 bytes (95% overhead!)
Efficiency: 4.9%
2. Compressed Stack (6LoWPAN):
802.15.4 MAC: 25 bytes
6LoWPAN (compressed IPv6 + UDP): 6 bytes
CoAP: 4 bytes
Payload: 4 bytes
Total: 39 bytes
Overhead: 35 bytes (90% overhead)
Efficiency: 10.3%
Improvement: 81 to 39 bytes (52% reduction)
3. MQTT Stack (assuming kept-alive TCP):
Ethernet MAC: 18 bytes (header + FCS)
IPv6: 40 bytes
TCP: 20 bytes
MQTT Fixed Header: 2 bytes
MQTT Variable Header: ~10 bytes (topic "home/temp")
Payload: 4 bytes
Total: 94 bytes
Overhead: 90 bytes (96% overhead)
Efficiency: 4.3%
4. HTTP Stack (minimum request):
Ethernet MAC: 18 bytes
IPv4: 20 bytes
TCP: 20 bytes
HTTP: ~100 bytes (GET /sensor/temp HTTP/1.1...)
Payload: 4 bytes
Total: 162 bytes
Overhead: 158 bytes (98% overhead)
Efficiency: 2.5%
Comparison: - 6LoWPAN + CoAP: 39 bytes (best) - MQTT: 94 bytes (2.4x CoAP) - HTTP: 162 bytes (4.2x CoAP)
Conclusion: For very small payloads, 6LoWPAN + CoAP is most efficient.660.1.3 Task 2: Calculate Transmissions for Battery Life
Sensor transmits every 5 minutes. Battery: 2000 mAh.
Given: - Radio TX: 5 mA - Data rate: 250 kbps (802.15.4) - Sleep: 5 uA
Calculate daily power consumption for: 1. CoAP (39 bytes, UDP) 2. MQTT (94 bytes, TCP with keep-alive)
Estimate battery life.
Click to see solution
Transmissions per day: 24 x 60 / 5 = 288
CoAP (UDP, 39 bytes):
TX time per message:
= 39 bytes x 8 bits / 250,000 bps
= 1.25 ms
Total TX time per day:
= 288 x 1.25 ms = 360 ms
Energy (TX):
= 5 mA x 0.36 s = 1.8 mA*s = 0.5 uAh
Energy (Sleep):
= 5 uA x (86,400 - 0.36) s / 3600 = 120 uAh
Total per day: 120.5 uAh = 0.12 mAh
Battery life: 2000 / 0.12 = 16,667 days = 45.7 years
MQTT (TCP keep-alive, 94 bytes + ACKs):
Assuming TCP connection kept open:
- Data: 94 bytes
- ACK: 40 bytes (IPv6 + TCP)
- Total per transmission: 134 bytes
TX+RX time per message:
= 134 bytes x 8 bits / 250,000 bps
= 4.3 ms
Total active time per day:
= 288 x 4.3 ms = 1.24 s
Energy (TX/RX):
= 5 mA x 1.24 s = 6.2 mA*s = 1.7 uAh
Energy (Sleep):
= 5 uA x (86,400 - 1.24) s / 3600 = 120 uAh
Total per day: 121.7 uAh = 0.122 mAh
Battery life: 2000 / 0.122 = 16,393 days = 44.9 years
Analysis: For infrequent transmission (every 5 min), sleep current dominates. Protocol overhead has minimal impact on battery life (both ~45 years, limited by battery self-discharge).
If transmitting every 10 seconds (8,640 times/day): - CoAP: 10.8 s active to 15 uAh/day to 133 days / 0.4 years - MQTT: 37.2 s active to 51.7 uAh/day to 38 days / 0.1 years
Conclusion: For frequent transmission, CoAP saves significant power (3.4x longer battery life).660.2 Python Implementations
660.2.1 Implementation 1: Protocol Stack Analyzer
This Python implementation calculates protocol overhead for different IoT stacks:
Expected Output:
######################################################################################
# IoT Protocol Stack Analysis (4-byte payload)
######################################################################################
==========================================================================================
PROTOCOL STACK COMPARISON (Payload: 4 bytes)
==========================================================================================
Stack Overhead Total Efficiency
(bytes) (bytes) (%)
------------------------------------------------------------------------------------------
HTTP over IPv4/Ethernet 104 108 3.70%
MQTT over IPv6/Ethernet 84 88 4.55%
CoAP over IPv6/802.15.4 77 81 4.94%
######################################################################################
# With 6LoWPAN Compression (802.15.4 + IPv6)
######################################################################################
==========================================================================================
PROTOCOL STACK COMPARISON (Payload: 4 bytes)
Using 6LoWPAN compression
==========================================================================================
Stack Overhead Total Efficiency
(bytes) (bytes) (%)
------------------------------------------------------------------------------------------
HTTP over IPv4/Ethernet 104 108 3.70%
MQTT over IPv6/Ethernet 84 88 4.55%
CoAP over IPv6/802.15.4 26 30 13.33%
======================================================================
DETAILED ANALYSIS: CoAP over IPv6/802.15.4
======================================================================
Protocol Overhead Breakdown:
----------------------------------------------------------------------
Layer Protocol Size (bytes)
----------------------------------------------------------------------
Data Link 802.15.4 25
Network IPv6 40
Transport UDP 8
Application CoAP 4
----------------------------------------------------------------------
TOTAL OVERHEAD 77
Payload 4
TOTAL PACKET 81
----------------------------------------------------------------------
Payload Efficiency: 4.94%
Overhead Ratio: 19.25x payload
======================================================================
DETAILED ANALYSIS: CoAP over IPv6/802.15.4
Using 6LoWPAN compression
======================================================================
Protocol Overhead Breakdown:
----------------------------------------------------------------------
Layer Protocol Size (bytes)
----------------------------------------------------------------------
Data Link 802.15.4 8
Network IPv6 6
Transport UDP 8
Application CoAP 4
----------------------------------------------------------------------
TOTAL OVERHEAD 26
Payload 4
TOTAL PACKET 30
----------------------------------------------------------------------
Payload Efficiency: 13.33%
Overhead Ratio: 6.50x payload
######################################################################################
# Impact of Payload Size (CoAP over IPv6/802.15.4 with compression)
######################################################################################
Payload (bytes) Overhead (bytes) Efficiency (%)
------------------------------------------------------------
4 26 13.33%
16 26 38.10%
64 26 71.11%
127 26 83.01%
Conclusion: Larger payloads improve efficiency!
Key Insights: - 6LoWPAN compression reduces CoAP stack from 81 to 30 bytes (62% reduction) - Payload efficiency increases with larger payloads (4 bytes = 13%, 127 bytes = 83%) - HTTP has worst efficiency (3.7%), CoAP best (13.3% with compression)
660.2.2 Implementation 2: Battery Life Impact Calculator
Expected Output:
##########################################################################################
# SCENARIO 1: Environmental Sensor (Every 5 minutes)
##########################################################################################
==========================================================================================
BATTERY LIFE COMPARISON (288 messages/day)
==========================================================================================
Battery: 2000 mAh
TX/RX current: 5 mA
Sleep current: 5 uA
Data rate: 250 kbps
==========================================================================================
Protocol Packet Daily Energy Battery Life
(bytes) (uAh) (days / years)
------------------------------------------------------------------------------------------
CoAP/UDP/IPv6/802.15.4 (compressed) 30 121.0 16528 days / 45.3 years
CoAP/UDP/IPv6/802.15.4 (uncompressed) 81 121.2 16500 days / 45.2 years
MQTT/TCP/IPv6/802.15.4 94 121.2 16493 days / 45.2 years
HTTP/TCP/IPv4/Ethernet 162 121.6 16454 days / 45.1 years
==========================================================================================
DETAILED BREAKDOWN: CoAP/UDP/IPv6/802.15.4 (compressed)
==========================================================================================
Packet size: 30 bytes
TX/RX time per message: 0.96 ms
Daily active time: 0.28 seconds
Daily TX/RX energy: 1.90 uAh
Daily sleep energy: 119.04 uAh
Daily total energy: 120.94 uAh
Battery life: 16528 days = 45.27 years
##########################################################################################
# SCENARIO 2: Real-Time Monitoring (Every 10 seconds)
##########################################################################################
==========================================================================================
BATTERY LIFE COMPARISON (8640 messages/day)
==========================================================================================
Battery: 2000 mAh
TX/RX current: 5 mA
Sleep current: 5 uA
Data rate: 250 kbps
==========================================================================================
Protocol Packet Daily Energy Battery Life
(bytes) (uAh) (days / years)
------------------------------------------------------------------------------------------
CoAP/UDP/IPv6/802.15.4 (compressed) 30 135.2 14792 days / 40.5 years
CoAP/UDP/IPv6/802.15.4 (uncompressed) 81 164.6 12145 days / 33.3 years
MQTT/TCP/IPv6/802.15.4 94 171.8 11640 days / 31.9 years
HTTP/TCP/IPv4/Ethernet 162 208.6 9584 days / 26.3 years
==========================================================================================
KEY INSIGHTS:
==========================================================================================
1. For infrequent transmission:
Sleep current dominates - Protocol choice has minimal impact
All protocols achieve >40 years (limited by battery self-discharge)
2. For frequent transmission:
Active time dominates - Protocol overhead critical!
CoAP (compressed): ~133 days
MQTT: ~38 days
HTTP: ~22 days
- CoAP provides 3.5x longer battery life vs MQTT
==========================================================================================
660.3 ESP32 Hands-On Labs
660.3.1 Lab 1: ESP32 Protocol Packet Analyzer
Objective: Analyze IoT protocol packets to understand overhead.
Hardware Required: - ESP32 development board - USB cable - Computer with Arduino IDE
See protocol efficiency in action! This simulator calculates overhead for different IoT protocol stacks, demonstrating why 6LoWPAN compression is critical for constrained devices.
Key Insights to Observe:
- CoAP/UDP/IPv6: Only 5.7% payload efficiency with 4-byte payload
- 6LoWPAN Compression: 85% header reduction (40 bytes to 6 bytes)
- Payload Aggregation: Larger payloads = dramatically better efficiency
- Compare Stacks: HTTP has highest overhead, CoAP with 6LoWPAN is most efficient
Expected Serial Output:
====================================================
IoT Protocol Packet Analyzer
ESP32 Protocol Overhead Inspector
====================================================
===================================================
PROTOCOL STACK OVERHEAD ANALYSIS (4-byte payload)
===================================================
-------------------------------------------------
Stack: CoAP/UDP/IPv6/Ethernet
-------------------------------------------------
Data Link: 14 bytes
Network: 40 bytes
Transport: 8 bytes
Application: 4 bytes
---------
Total Overhead: 66 bytes
Payload: 4 bytes
=========
TOTAL PACKET: 70 bytes
Payload Efficiency: 5.71%
Overhead Ratio: 16.50x payload
[... similar for other stacks ...]
===================================================
6LoWPAN COMPRESSION BENEFIT
===================================================
IPv6 Header Compression:
Uncompressed IPv6: 40 bytes
- Version (4 bits)
- Traffic Class (8 bits)
- Flow Label (20 bits)
- Payload Length (16 bits)
- Next Header (8 bits)
- Hop Limit (8 bits)
- Source Address (128 bits = 16 bytes)
- Destination Address (128 bits = 16 bytes)
6LoWPAN Compressed: 6 bytes (85% reduction!)
- Context-based compression
- Link-local addresses derived from MAC
- Omit hop limit (use default)
- Omit flow label (not needed)
Total Savings:
Before: 40 + 25 = 65 bytes (IPv6 + 802.15.4)
After: 6 + 8 = 14 bytes (compressed)
Savings: 51 bytes = 78% reduction
===================================================
PAYLOAD SIZE IMPACT ON EFFICIENCY
===================================================
CoAP/UDP/IPv6/802.15.4 (6LoWPAN compressed):
Fixed overhead: 22 bytes
Payload Total Packet Efficiency
(bytes) (bytes) (%)
----------------------------------
4 26 15.4%
8 30 26.7%
16 38 42.1%
32 54 59.3%
64 86 74.4%
105 127 82.7%
Key Insight: Larger payloads dramatically improve efficiency!
Aggregate multiple sensor readings when possible.
660.4 Summary
Protocol Overhead Analysis: - 6LoWPAN + CoAP: 39 bytes (10% efficiency for 4-byte payload) - MQTT: 94 bytes (4% efficiency) - HTTP: 162 bytes (2.5% efficiency) - Larger payloads improve efficiency (aggregate sensor readings!)
Battery Life Impact: - Infrequent (every 5 min): Minimal difference (~45 years both) - Frequent (every 10 sec): CoAP 3.4x better than MQTT - Sleep current dominates for infrequent transmission - Protocol overhead critical for frequent transmission
6LoWPAN Compression: - Reduces IPv6 header from 40 to 6 bytes (85% savings) - Enables IPv6 on constrained 802.15.4 networks - Critical for achieving 10+ year battery life - Context-based compression derives addresses from MAC
Practical Guidelines: - Use CoAP for battery-powered sensors - Aggregate multiple readings to improve efficiency - Consider 6LoWPAN compression for any 802.15.4 deployment - TCP keep-alives drain battery - use UDP when possible
660.5 Whatโs Next?
Continue to Real-World Protocol Examples to see how these concepts apply in practical IoT deployments with detailed use case analysis.