RFC 7228 defines constrained device classes, but choosing the right protocol stack for each class isn’t obvious. Use this framework:
| 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:
| 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