Protocol Design
Purpose
Select and design the communication protocol stack for an IoT/embedded system, including physical layer selection, transport protocol, application protocol, and security layer.
Inputs
- Device hardware capabilities (radio modules available)
- Communication requirements (range, bandwidth, latency, power)
- Network topology (star, mesh, point-to-point)
- Security requirements (encryption, authentication, integrity)
- Ecosystem requirements (Matter certification, HomeKit, Alexa)
Process
Step 1: Define Communication Requirements
Quantify what the protocol must deliver:
- Range: Indoor (10m), building (50m), campus (500m), wide-area (km+)
- Bandwidth: Bytes/second needed for typical and peak traffic
- Latency: Maximum acceptable end-to-end delay
- Power budget: mA available for radio operations, duty cycle
- Topology: Star (hub-spoke), mesh (multi-hop), point-to-point
- Device density: How many devices in one radio neighborhood
Step 2: Select Physical/Link Layer
Choose the radio technology:
| Protocol |
Range |
Bandwidth |
Power |
Topology |
Best For |
| BLE 5.0 |
50m |
2Mbps |
Low |
Star/mesh |
Wearables, sensors, phones |
| Thread |
50m |
250kbps |
Low |
Mesh |
Home automation (Matter) |
| Zigbee |
100m |
250kbps |
Low |
Mesh |
Legacy home automation |
| Wi-Fi |
50m |
High |
High |
Star |
High-bandwidth, powered devices |
| LoRaWAN |
15km |
0.3-50kbps |
Very low |
Star |
Wide-area, low-frequency |
| Cellular (LTE-M/NB-IoT) |
km+ |
Moderate |
Medium |
Star |
Asset tracking, remote |
Step 3: Select Application Protocol
Choose how data is structured and exchanged:
- MQTT: Pub/sub, lightweight, great for telemetry. Needs TCP (Wi-Fi/cellular).
- CoAP: REST-like over UDP, ideal for constrained devices. Built-in discovery.
- HTTP/REST: Universal but heavy. Only for powered devices with good connectivity.
- Custom binary: Maximum efficiency but maintenance burden. Use Protobuf or CBOR instead of raw binary.
Step 4: Design Security Layer
Layer security into the stack:
- Transport encryption: TLS 1.3 (TCP), DTLS (UDP), or link-layer encryption (BLE bonding)
- Authentication: Device certificates, pre-shared keys, or OAuth 2.0 device flow
- Integrity: Message signing, sequence numbers to prevent replay
- Key management: How are keys provisioned, rotated, and revoked?
Step 5: Design Message Format
Define the wire format:
- Serialization: JSON (readable, large), CBOR (compact, schemaless), Protobuf (compact, schema-required)
- Envelope: Header (device ID, message type, sequence, timestamp) + payload
- Size budget: Maximum message size for the chosen transport
- Fragmentation: How to handle messages larger than MTU
Step 6: Design Error Handling and Resilience
Plan for communication failures:
- Retry strategy: Exponential backoff with jitter
- QoS levels: At-most-once, at-least-once, exactly-once — which is needed?
- Offline queuing: Buffer messages during disconnection, sync on reconnect
- Connection management: Keepalive intervals, reconnection strategy
Output Format
# Protocol Architecture
## Requirements Summary
| Requirement | Value |
|-------------|-------|
| Range | [X meters/km] |
| Bandwidth | [X bytes/sec] |
| Latency | [X ms max] |
| Power budget | [X mA avg] |
| Topology | [Star/Mesh/P2P] |
## Protocol Stack
| Layer | Choice | Rationale |
|-------|--------|-----------|
| Physical/Link | [BLE/Thread/Wi-Fi/etc.] | [Why] |
| Transport | [TCP/UDP/none] | [Why] |
| Security | [TLS/DTLS/link-layer] | [Why] |
| Application | [MQTT/CoAP/custom] | [Why] |
| Serialization | [JSON/CBOR/Protobuf] | [Why] |
## Message Format
[Header: device_id (4B) | msg_type (1B) | seq (2B) | timestamp (4B)]
[Payload: CBOR-encoded application data]
[Total: ~128 bytes typical, 512 bytes max]
## Security Design
| Aspect | Approach |
|--------|----------|
| Encryption | [Method] |
| Authentication | [Method] |
| Key management | [Provisioning and rotation strategy] |
## Error Handling
| Scenario | Strategy |
|----------|----------|
| Message lost | [Retry/QoS approach] |
| Disconnection | [Offline queue + sync] |
| Server unreachable | [Backoff + local operation] |
Quality Checks
Evolution Notes
1---2name: protocol-design3department: "sentinel"4description: "Wireless protocol selection, stack design, and interoperability"5version: 16triggers:7 - "BLE"8 - "MQTT"9 - "Matter"10 - "Thread"11 - "Zigbee"12 - "LoRa"13 - "CoAP"14 - "protocol"15 - "wireless"16 - "radio"17---1819# Protocol Design2021## Purpose2223Select and design the communication protocol stack for an IoT/embedded system, including physical layer selection, transport protocol, application protocol, and security layer.2425## Inputs2627- Device hardware capabilities (radio modules available)28- Communication requirements (range, bandwidth, latency, power)29- Network topology (star, mesh, point-to-point)30- Security requirements (encryption, authentication, integrity)31- Ecosystem requirements (Matter certification, HomeKit, Alexa)3233## Process3435### Step 1: Define Communication Requirements3637Quantify what the protocol must deliver:38- **Range:** Indoor (10m), building (50m), campus (500m), wide-area (km+)39- **Bandwidth:** Bytes/second needed for typical and peak traffic40- **Latency:** Maximum acceptable end-to-end delay41- **Power budget:** mA available for radio operations, duty cycle42- **Topology:** Star (hub-spoke), mesh (multi-hop), point-to-point43- **Device density:** How many devices in one radio neighborhood4445### Step 2: Select Physical/Link Layer4647Choose the radio technology:4849| Protocol | Range | Bandwidth | Power | Topology | Best For |50|----------|-------|-----------|-------|----------|----------|51| BLE 5.0 | 50m | 2Mbps | Low | Star/mesh | Wearables, sensors, phones |52| Thread | 50m | 250kbps | Low | Mesh | Home automation (Matter) |53| Zigbee | 100m | 250kbps | Low | Mesh | Legacy home automation |54| Wi-Fi | 50m | High | High | Star | High-bandwidth, powered devices |55| LoRaWAN | 15km | 0.3-50kbps | Very low | Star | Wide-area, low-frequency |56| Cellular (LTE-M/NB-IoT) | km+ | Moderate | Medium | Star | Asset tracking, remote |5758### Step 3: Select Application Protocol5960Choose how data is structured and exchanged:61- **MQTT:** Pub/sub, lightweight, great for telemetry. Needs TCP (Wi-Fi/cellular).62- **CoAP:** REST-like over UDP, ideal for constrained devices. Built-in discovery.63- **HTTP/REST:** Universal but heavy. Only for powered devices with good connectivity.64- **Custom binary:** Maximum efficiency but maintenance burden. Use Protobuf or CBOR instead of raw binary.6566### Step 4: Design Security Layer6768Layer security into the stack:69- **Transport encryption:** TLS 1.3 (TCP), DTLS (UDP), or link-layer encryption (BLE bonding)70- **Authentication:** Device certificates, pre-shared keys, or OAuth 2.0 device flow71- **Integrity:** Message signing, sequence numbers to prevent replay72- **Key management:** How are keys provisioned, rotated, and revoked?7374### Step 5: Design Message Format7576Define the wire format:77- **Serialization:** JSON (readable, large), CBOR (compact, schemaless), Protobuf (compact, schema-required)78- **Envelope:** Header (device ID, message type, sequence, timestamp) + payload79- **Size budget:** Maximum message size for the chosen transport80- **Fragmentation:** How to handle messages larger than MTU8182### Step 6: Design Error Handling and Resilience8384Plan for communication failures:85- **Retry strategy:** Exponential backoff with jitter86- **QoS levels:** At-most-once, at-least-once, exactly-once — which is needed?87- **Offline queuing:** Buffer messages during disconnection, sync on reconnect88- **Connection management:** Keepalive intervals, reconnection strategy8990## Output Format9192```markdown93# Protocol Architecture9495## Requirements Summary96| Requirement | Value |97|-------------|-------|98| Range | [X meters/km] |99| Bandwidth | [X bytes/sec] |100| Latency | [X ms max] |101| Power budget | [X mA avg] |102| Topology | [Star/Mesh/P2P] |103104## Protocol Stack105| Layer | Choice | Rationale |106|-------|--------|-----------|107| Physical/Link | [BLE/Thread/Wi-Fi/etc.] | [Why] |108| Transport | [TCP/UDP/none] | [Why] |109| Security | [TLS/DTLS/link-layer] | [Why] |110| Application | [MQTT/CoAP/custom] | [Why] |111| Serialization | [JSON/CBOR/Protobuf] | [Why] |112113## Message Format114```115[Header: device_id (4B) | msg_type (1B) | seq (2B) | timestamp (4B)]116[Payload: CBOR-encoded application data]117[Total: ~128 bytes typical, 512 bytes max]118```119120## Security Design121| Aspect | Approach |122|--------|----------|123| Encryption | [Method] |124| Authentication | [Method] |125| Key management | [Provisioning and rotation strategy] |126127## Error Handling128| Scenario | Strategy |129|----------|----------|130| Message lost | [Retry/QoS approach] |131| Disconnection | [Offline queue + sync] |132| Server unreachable | [Backoff + local operation] |133```134135## Quality Checks136137- [ ] Protocol selection is justified against requirements (not just "we always use MQTT")138- [ ] Power consumption of radio operations is calculated against battery budget139- [ ] Security covers encryption, authentication, and key management140- [ ] Message format fits within the chosen transport's MTU141- [ ] Error handling addresses disconnection, retry, and offline operation142- [ ] Ecosystem requirements (Matter, HomeKit) are satisfied by protocol choice143144## Evolution Notes145<!-- Observations appended after each use -->