Back
Loading views...Thread
Thread
Overview
Thread is an IPv6-based, low-power mesh networking protocol designed for smart home and building IoT devices. Built on IEEE 802.15.4, it provides native IP connectivity, self-healing mesh routing, and integrates with Matter (formerly Project CHIP).
1. Theory & Fundamentals
- Based on IEEE 802.15.4 (same PHY as Zigbee) at 2.4 GHz
- Full IPv6 stack: 6LoWPAN compression enables IPv6 over 802.15.4
- Roles: Leader, Router, End Device (sleepy/non-sleepy), Border Router
- Mesh: Self-healing; Routers forward packets; Leader manages network
- Security: DTLS with pre-shared key; network key AES-128
- Border Router: Connects Thread mesh to IP network (Wi-Fi/Ethernet)
- Matter protocol runs on top of Thread
2. Frame / Packet Structure
Thread network layers:
Application (Matter/CoAP/MQTT)
UDP / TCP
IPv6
6LoWPAN (IP over 802.15.4)
IEEE 802.15.4 MAC
IEEE 802.15.4 PHY
MLE (Mesh Link Establishment) frames:
Discover, Advertise, Request, Accept, Reject
Child Update Request/Response, Data Request
Thread Network Data:
Leader data: Partition ID, Router ID mask, network prefixes
Routing table: Each router knows neighbors' costs
3. Protocol Mechanics
- RLOC (Routing Locator): IPv6 address encoding router ID + child ID
- ALOC (Anycast Locator): For special functions (DHCPv6, services)
- EID (Endpoint Identifier): Application-layer address (stable)
- Border Router: Provides external connectivity, route propagation
- Commissioner: Authenticates new devices joining network
- PSKc: Pre-Shared Key for commissioner (network-level)
4. Hardware Implementation
- SoC: nRF52840 (Nordic), EFR32MG21 (Silicon Labs), CC2652 (TI)
- OpenThread: Open-source Thread stack (Google, maintained by Thread Group)
- Border Router: Raspberry Pi + nRF52840 dongle + OTBR image
- Antenna: Same as Zigbee (PCB trace for 2.4 GHz)
- Matter SDK uses OpenThread as transport
5. Register-Level / Configuration
// OpenThread (nRF52840 SDK)
otInstance *instance = otInstanceInitSingle();
otIp6SetEnabled(instance, true);
otThreadSetEnabled(instance, true);
// Set network parameters
otThreadSetNetworkName(instance, "MyNetwork");
otThreadSetChannel(instance, 15);
otThreadSetMasterKey(instance, &masterKey);
// Start as router
otThreadBecomeRouter(instance);
// Send UDP datagram
otUdpSend(instance, &socket, &message, &msgInfo);
6. Driver / Software Development
- Initialize hardware peripheral or SoC block
- Implement send/receive with interrupt or DMA
- Handle errors: timeout, CRC, NAK, bus-off
- Use circular buffers for RX data flow
- Implement retry logic for reliability
7. Debugging & Testing
- OpenThread CLI: Serial command line interface for testing
- Wireshark with 802.15.4 plugin for packet capture
- OTBR Web UI: Border router status, topology visualization
- Common issues: Wrong channel; network key mismatch; border router not propagating routes
- 'thread state' command shows node role
8. Real-World Applications
- Matter smart home devices (lights, locks, thermostats)
- Building automation sensors
- Industrial IoT edge devices
- Healthcare monitoring devices
- Smart energy meters
9. Advanced Topics & Edge Cases
- Matter: Application layer standard (Apple, Google, Amazon) runs on Thread
- Thread 1.3: Enhanced Border Router discovery, DNS-SD
- Sleepy End Device (SED): Polls parent router for messages; battery-friendly
- SSED (Synchronized SED): Wakes on schedule; even lower power
- Multi-hop: Up to 32 hops in mesh; practical limit ~5 for latency
10. Standards & Variants
| Protocol | PHY | IP | Mesh | Notes |
|---|---|---|---|---|
| Thread | 802.15.4 | IPv6 | Yes | Matter-compatible |
| Zigbee | 802.15.4 | No | Yes | ZHA/ZLL |
| BLE Mesh | BLE | No | Yes | Flooding mesh |
| Wi-Fi | 802.11 | IPv4/6 | No | High power |
๐ก Practical Examples
Ex 1: Join network
otThreadSetChannel(inst, 15);
otThreadSetMasterKey(inst, &key);
otThreadSetEnabled(inst, true); // Joins as end device or router
Ex 2: CoAP request
otCoapSendRequest(inst, &msg, &dest, responseHandler, context);
Ex 3: Border Router setup
Install OTBR on Raspberry Pi, connect nRF52840 via USB, configure firewall rules for IPv6.
๐งช Practice Questions
Beginner
- What frequency does Thread use?
- What is the difference between a Thread Router and End Device?
- What is a Border Router in Thread?
- What application protocol runs on top of Thread?
- What IP version does Thread use natively?
Intermediate
- Explain Thread network formation and leader election.
- How does 6LoWPAN compress IPv6 headers for 802.15.4?
- Implement a Thread CoAP server on nRF52840.
- How does Thread handle router table updates?
- What is the role of a Thread Commissioner?
Advanced
- Build a Thread border router with OpenThread on Raspberry Pi.
- Implement a Matter device over Thread (light or switch).
- Optimize Thread for sleepy end device battery life.
- Design a Thread mesh for a 50-device building.
- Debug Thread network partition and merge behavior.
Projects
- Thread Sensor: Temperature node on nRF52840, reports via CoAP.
- Border Router: Raspberry Pi OTBR connecting Thread mesh to internet.
- Matter Light: Implement Matter on-off light over Thread network.
Checklist
- [ ] Explain Thread roles (Leader, Router, ED, Border Router)
- [ ] Initialize OpenThread stack on nRF52840
- [ ] Join Thread network with correct parameters
- [ ] Send/receive UDP over Thread
- [ ] Implement CoAP server
- [ ] Set up OpenThread Border Router
- [ ] Debug with OpenThread CLI
- [ ] Implement sleepy end device
- [ ] Integrate with Matter application layer
- [ ] Monitor network topology