Embedded Communication

Wireless Protocol Landscape
Choosing a wireless protocol involves tradeoffs between range, power consumption, data rate, and network topology.
| Protocol | Range | Data Rate | Power | Topology | Best For | |---|---|---|---|---|---| | BLE 5.x | 100-400m | 2 Mbps | Very low | Star, mesh | Wearables, beacons, sensors | | Zigbee | 10-100m | 250 kbps | Low | Mesh | Home automation, lighting | | Thread | 10-100m | 250 kbps | Low | Mesh | Smart home (with Matter) | | LoRa | 2-15 km | 0.3-50 kbps | Very low | Star-of-stars | Agriculture, utilities, asset tracking | | NB-IoT | 10+ km | 250 kbps DL | Medium | Cellular star | Metering, city infrastructure | | Wi-Fi | 50-100m | 1+ Gbps | High | Star | Streaming, high-bandwidth IoT | | Matter | Depends on transport | Varies | Varies | Mesh/star | Unified smart home standard |
Bluetooth Low Energy (BLE)
BLE is optimized for intermittent data transfer with minimal power consumption. A BLE device can run for years on a coin cell battery.
Key Concepts
- GAP (Generic Access Profile): controls advertising and connections
- GATT (Generic Attribute Profile): defines data exchange via services and characteristics
- Advertising: device broadcasts small packets (31 bytes) periodically
- Connections: bidirectional, reliable data exchange between central and peripheral
GATT Hierarchy
Profile
└── Service (UUID: 0x180F = Battery Service)
└── Characteristic (UUID: 0x2A19 = Battery Level)
├── Value: 85 (percent)
├── Properties: Read, Notify
└── Descriptor (Client Characteristic Configuration)
BLE on Embedded Rust (nRF52 with SoftDevice)
// BLE GATT service definition (UUID = "180f" Battery Service)
STRUCTURE BatteryService
battery_level: byte // characteristic UUID "2a19", read + notify
ASYNC TASK BLE_TASK(softdevice, server)
LOOP
conn ← AWAIT ADVERTISE_CONNECTABLE(softdevice, adv, config)
// Update battery level and notify connected client
server.battery.SET_BATTERY_LEVEL(conn, 85)
Zigbee
IEEE 802.15.4-based mesh protocol for low-power, low-data-rate networks. Supports up to 65,000 nodes per network.
Node Roles
- Coordinator: forms the network, assigns addresses, one per network
- Router: relays messages, extends network range, must be mains-powered
- End Device: sleeps most of the time, communicates through parent router
Zigbee Mesh Routing
Messages hop through routers to reach distant nodes. If one path fails, the mesh self-heals by finding alternative routes. AODV (Ad-hoc On-demand Distance Vector) is the typical routing protocol.
LoRa and LoRaWAN
LoRa (Physical Layer)
Chirp Spread Spectrum (CSS) modulation that trades data rate for range and noise immunity. Operates in unlicensed ISM bands (868 MHz EU, 915 MHz US, 433 MHz Asia).
LoRaWAN (Network Layer)
Defines the network architecture, device classes, and MAC protocol.
End Devices ──── Gateway ──── Network Server ──── Application Server
(LoRa radio) (LoRa+IP) (deduplication, (business logic)
routing, MAC)
Device Classes
| Class | Receive Windows | Latency | Power | Use Case | |---|---|---|---|---| | A | After each uplink only | High | Lowest | Sensors, meters | | B | Scheduled (beacon-synced) | Medium | Medium | Actuators | | C | Continuous listening | Low | Highest | Powered actuators, gateways |
LoRa Parameters
| Spreading Factor | Range | Data Rate | Airtime | |---|---|---|---| | SF7 | Shortest | ~5.5 kbps | ~50 ms | | SF12 | Longest | ~0.3 kbps | ~1.5 s |
Higher spreading factor = longer range but lower throughput and more airtime (regulatory limits apply).
NB-IoT (Narrowband IoT)
Cellular LPWAN technology that operates in licensed spectrum alongside LTE:
- Deployed by mobile operators -- no gateway infrastructure needed
- Deep indoor penetration (20 dB improvement over LTE)
- Power Saving Mode (PSM) and extended Discontinuous Reception (eDRX) for battery life
- Ideal for devices sending small amounts of data infrequently
Thread
IPv6-based mesh networking protocol for smart home devices:
- Built on IEEE 802.15.4 radio (same as Zigbee)
- Native IP connectivity -- no application-layer gateway needed
- Border Router connects Thread mesh to Wi-Fi/Ethernet networks
- Self-healing mesh with router-eligible devices
- Low power with Sleepy End Devices
Matter
A unifying smart home standard that runs over Thread, Wi-Fi, and Ethernet:
- Common application layer across transport protocols
- Device types defined by data models (lights, locks, thermostats)
- Secure commissioning via QR codes
- Multi-admin: devices can be controlled by multiple ecosystems simultaneously
- Backed by Apple, Google, Amazon, Samsung, and others
Application-Layer Protocols
MQTT (Message Queuing Telemetry Transport)
Publish-subscribe protocol designed for constrained devices and unreliable networks.
Publisher ──── Broker ──── Subscriber
(sensor) (server) (dashboard)
Topic: "home/livingroom/temperature"
Payload: "23.5"
QoS: 0 (at most once), 1 (at least once), 2 (exactly once)
MQTT Features
- Retained messages: broker stores last message per topic for new subscribers
- Last Will and Testament (LWT): broker publishes a message if client disconnects unexpectedly
- Keep-alive: periodic PINGREQ/PINGRESP to detect dead connections
- Topic wildcards:
+(single level),#(multi level)
MQTT on Embedded
// MQTT client for embedded (no dynamic allocation, buffer size 256)
mqtt ← MQTT_NEW(socket, clock, broker_config, buffer_size ← 256)
// Publish sensor data
MQTT_PUBLISH(mqtt,
payload ← "23.5",
topic ← "sensors/temp",
qos ← AtLeastOnce)
// Poll for incoming messages
MQTT_POLL(mqtt, CALLBACK(client, topic, payload, properties):
IF topic = "actuators/led" THEN
SET_LED(payload[0] = '1')
)
CoAP (Constrained Application Protocol)
RESTful protocol for constrained devices, built on UDP instead of TCP:
| Feature | MQTT | CoAP | |---|---|---| | Transport | TCP | UDP | | Pattern | Pub/Sub | Request/Response (REST) | | Header size | 2+ bytes | 4 bytes | | Discovery | No | Yes (/.well-known/core) | | Observe | Via subscribe | Built-in observe option | | Security | TLS | DTLS |
CoAP maps naturally to HTTP methods (GET, POST, PUT, DELETE) and supports resource observation for push updates.
Mesh Networking
Mesh Topology Benefits
- Self-healing: automatically reroutes around failed nodes
- Range extension: each node can relay for others
- Scalability: add nodes without infrastructure changes
Mesh Challenges
- Increased latency (multi-hop)
- Higher power for routing nodes
- Routing table overhead
- Potential for routing loops
BLE Mesh
- Managed flooding (no routing tables needed)
- Publish/subscribe model for group communication
- Up to 32,767 nodes
- Used in commercial lighting and building automation
Gateway Design
Gateways bridge constrained device networks to IP infrastructure.
Sensor ─── (BLE/Zigbee/LoRa) ──── Gateway ──── (Wi-Fi/Ethernet) ──── Cloud
MCU Linux SBC Server
Battery Mains power
Constrained Protocol translation
Gateway Responsibilities
- Protocol translation: convert sensor protocol to MQTT/HTTP
- Data aggregation: batch messages to reduce cloud traffic
- Local processing: edge filtering, anomaly detection
- Security: TLS termination, device authentication
- Store and forward: buffer data during network outages
- Device management: firmware updates, configuration
Gateway Architecture
┌─────────────────────────────────────────┐
│ Gateway │
│ │
│ ┌──────────┐ ┌──────────┐ ┌───────┐ │
│ │ Radio │ │ Protocol │ │ Cloud │ │
│ │ Driver │──│ Handler │──│ Client│ │
│ │(BLE/LoRa)│ │(parse, │ │(MQTT/ │ │
│ │ │ │ validate)│ │ HTTP) │ │
│ └──────────┘ └──────────┘ └───────┘ │
│ │ │ │ │
│ ┌──────────────────────────────────┐ │
│ │ Local Storage / Message Queue │ │
│ └──────────────────────────────────┘ │
└─────────────────────────────────────────┘
Key Takeaways
- Protocol selection depends on range, power budget, data rate, and infrastructure availability.
- BLE dominates short-range personal devices; LoRa excels at long-range, low-power sensing.
- Thread and Matter are converging the smart home on IP-based, interoperable mesh networking.
- MQTT's pub/sub model suits IoT's many-to-many data flows; CoAP fits resource-constrained RESTful interactions.
- Gateways are critical infrastructure that handle protocol translation, security, and reliability.