Lab Review: A retrospective analysis of hands-on exercises to consolidate learning and identify gaps before assessment
Packet Trace Analysis: Interpreting captured network frames to verify protocol behaviour and measure overhead
Configuration Verification: Checking that protocol parameters (QoS, topic hierarchy, CoAP options) match design requirements
Error Diagnosis: Identifying the root cause of failed connections or dropped packets using logs and traces
Performance Baseline: The measured latency and throughput of a correctly configured protocol stack, used as a reference for detecting degradation
Lab Report Structure: The standard format for documenting observations, measurements, and conclusions from a practical exercise
Peer Review: Evaluating another student’s lab configuration and results to identify errors and learn alternative approaches
37.1 In 60 Seconds
This advanced lab builds ESP32-based packet analyzers to inspect IoT protocol structures at the byte level. You will calculate header sizes, implement tools that decode protocol fields in real-time, diagnose communication problems through low-level analysis, and optimize message payloads to minimize protocol overhead on constrained networks.
37.2 Learning Objectives
By the end of this chapter, you will be able to:
Calculate protocol overhead: Determine header sizes and efficiency for different protocol stacks quantitatively
Construct packet analyzers: Implement ESP32 tools to inspect protocol structures at byte level
Diagnose protocol issues: Use low-level analysis to identify communication problems
Optimize message payloads: Design efficient payloads that minimize protocol overhead on constrained networks
What is protocol overhead? Protocol overhead is the “wrapper” that protocols add to your actual data. Like shipping a small item in a big box with lots of packing material, protocols add headers that can be much larger than your actual payload.
Why does this matter? For IoT devices: - Battery life: More bytes = more radio time = shorter battery life - Network capacity: Less overhead = more devices per gateway - Cost: Less airtime = lower cellular/network costs
Example: Sending a 4-byte temperature reading (23.5°C) might require: - 66 bytes total with uncompressed IPv6 - 26 bytes total with 6LoWPAN compression - That’s 40 bytes saved per message!
Putting Numbers to It
Protocol efficiency in this lab is measured as payload ratio:
Objective: Run the protocol packet analyzer in a Wokwi simulator to see how different IoT protocol stacks (CoAP/UDP/IPv6, MQTT/TCP/IPv6, HTTP/TCP/IPv4) compare in overhead, and why 6LoWPAN compression is critical for constrained 802.15.4 networks.
Copy the Lab 1 code above into the Wokwi editor and click Play. The serial monitor will display the complete overhead analysis for all four protocol stacks, 6LoWPAN compression benefits, and payload efficiency tables.
What to Observe:
CoAP/UDP/IPv6 efficiency is only 5.71% for a 4-byte payload (66 bytes of headers for 4 bytes of data) – this is why payload aggregation matters
6LoWPAN compression reduces IPv6+802.15.4 overhead from 65 bytes to 14 bytes (78% reduction), making IPv6 feasible on tiny radios
MQTT/TCP vs CoAP/UDP: MQTT/TCP adds 20 bytes of TCP overhead that CoAP/UDP avoids, but MQTT’s broker-based pub/sub is better for fan-out scenarios
Payload size impact: Efficiency jumps from 15.4% (4 bytes) to 82.7% (105 bytes) with the same 22-byte compressed header – always batch sensor readings when possible
6LoWPAN compression is essential: Reduces IPv6 overhead from 40 bytes to 6 bytes (85% reduction)
Protocol stack matters more than application header: MQTT’s 2-byte header is smaller than CoAP’s 4-byte header, but MQTT requires TCP (20 bytes) vs UDP (8 bytes)
Payload aggregation improves efficiency:
4-byte payload: 15.4% efficiency
64-byte payload: 74.4% efficiency
Consider batching sensor readings!
HTTP is unsuitable for constrained devices: 104+ bytes of overhead for tiny payloads
Try It: Protocol Overhead Explorer
Adjust the payload size and see how efficiency changes across protocol stacks in real time.
For real protocol analysis, use Wireshark with these filters:
CoAP Traffic:
coap && ip.dst == 192.168.1.100
MQTT Traffic:
mqtt && tcp.port == 1883
6LoWPAN over 802.15.4:
wpan && 6lowpan
Key Fields to Analyze:
Frame length (total bytes on wire)
Protocol header sizes at each layer
Payload extraction and efficiency calculation
Decision Framework: When to Use 6LoWPAN Compression
Evaluate your network characteristics against this framework to determine if 6LoWPAN is essential, beneficial, or unnecessary:
Network Layer
MTU Size
Device RAM
6LoWPAN Decision
Rationale
IEEE 802.15.4
127 bytes
< 64 KB
Essential
Without compression, 40-byte IPv6 + 8-byte UDP leaves only 79 bytes for application data. With compression (6 + 4 bytes), you get 117 bytes—a 48% increase
Bluetooth LE
27-251 bytes
< 256 KB
Highly recommended
BLE 4.x has 27-byte MTU; BLE 5.x supports up to 251 bytes but many devices still use 27. Compression critical for smaller MTUs
Thread
127 bytes
< 256 KB
Essential
Thread IS based on 6LoWPAN by design. Using Thread without 6LoWPAN violates the specification
Wi-Fi
1500 bytes
> 1 MB
Not needed
40-byte IPv6 header is only 2.7% of 1500-byte MTU. Compression overhead exceeds benefits
Frame: 127 bytes total
- MAC header: 25 bytes
- IPv6 header: 40 bytes
- UDP header: 8 bytes
- CoAP header: 4 bytes
- Payload: 4 bytes
- Security (AES): 16 bytes
- FCS: 2 bytes
Total overhead: 95 bytes
Available payload: 32 bytes maximum
Efficiency: 4/127 = 3.1%
With 6LoWPAN (same 4-byte reading):
Frame: 127 bytes total
- MAC header: 25 bytes (unchanged)
- 6LoWPAN IPHC: 2 bytes (compressed IPv6)
- NHC UDP: 4 bytes (compressed UDP)
- CoAP header: 4 bytes (unchanged)
- Payload: 4 bytes
- Security (AES): 16 bytes (unchanged)
- FCS: 2 bytes (unchanged)
Total overhead: 53 bytes
Available payload: 74 bytes maximum
Efficiency: 4/127 = 3.1% (same for tiny payload)
BUT maximum payload increased from 32 → 74 bytes (+130%)
Key insight: 6LoWPAN’s value isn’t always in improving efficiency for tiny payloads—it’s in increasing maximum usable payload. For an 802.15.4 network, 6LoWPAN enables sending 74-byte application messages instead of being capped at 32 bytes. This allows payload batching, reducing transmission frequency by 2.3×, which directly extends battery life by the same factor.
Implementation note: Most 6LoWPAN stacks require 16-32 KB RAM for the compression context and fragmentation/reassembly buffers. If your MCU has only 8 KB RAM, 6LoWPAN may not fit. :::
Match Lab Results to Key Insights
Order the Protocol Packet Analysis Steps
Common Pitfalls
1. Reviewing Labs Without Repeating Key Steps
Reading notes about a lab is not the same as redoing the critical steps. Fix: re-run the broker startup, publish, and subscribe sequence to confirm understanding before the assessment.
2. Not Comparing Results Across Different Protocol Labs
Students review each lab in isolation and miss cross-protocol patterns. Fix: create a comparison table listing measured latency, overhead, and packet loss for each protocol lab.
3. Ignoring Error Messages During Review
“It worked in the end” without understanding the error messages means the same errors will reappear in the assessment. Fix: document every error encountered and its solution in the lab review notes.
Label the Diagram
Code Challenge
37.7 Summary
Key Takeaways from Labs
ESP32 Packet Analyzer (Lab 1):
Demonstrated header sizes for common protocol stacks
6LoWPAN compression: 40-byte IPv6 header to 6 bytes (85% reduction)
Protocol efficiency varies from 3.7% (HTTP) to 82.7% (max CoAP payload)
Overhead Calculator (Lab 2):
LoRaWAN most efficient for small payloads (23.5% at 4 bytes)
CoAP/UDP/6LoWPAN best for IP-based constrained networks
HTTP unsuitable for battery-powered IoT devices
Battery Life Impact:
At low TX frequencies (e.g., every 10 min), sleep current dominates and protocol choice has minimal impact
At high TX frequencies (e.g., every 10 sec), protocol overhead becomes significant — use CoAP/UDP over MQTT/TCP
Aggregate payloads when possible to improve efficiency
Optimization Strategies:
Use 6LoWPAN for 802.15.4 networks (mandatory for efficiency)
Prefer UDP over TCP for constrained devices
Batch sensor readings to maximize payload efficiency
Consider LoRaWAN MAC-layer for LPWAN (no IP overhead)
Payload efficiency improves dramatically with larger payloads (15.4% at 4 bytes → 82.7% at 105 bytes)
Battery life calculations require analyzing transmission energy, sleep current, and protocol overhead – sleep current often dominates at low TX frequencies