Back

Thread

Loading views...

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

  1. Matter smart home devices (lights, locks, thermostats)
  2. Building automation sensors
  3. Industrial IoT edge devices
  4. Healthcare monitoring devices
  5. 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

  1. What frequency does Thread use?
  2. What is the difference between a Thread Router and End Device?
  3. What is a Border Router in Thread?
  4. What application protocol runs on top of Thread?
  5. What IP version does Thread use natively?

Intermediate

  1. Explain Thread network formation and leader election.
  2. How does 6LoWPAN compress IPv6 headers for 802.15.4?
  3. Implement a Thread CoAP server on nRF52840.
  4. How does Thread handle router table updates?
  5. What is the role of a Thread Commissioner?

Advanced

  1. Build a Thread border router with OpenThread on Raspberry Pi.
  2. Implement a Matter device over Thread (light or switch).
  3. Optimize Thread for sleepy end device battery life.
  4. Design a Thread mesh for a 50-device building.
  5. Debug Thread network partition and merge behavior.

Projects

  1. Thread Sensor: Temperature node on nRF52840, reports via CoAP.
  2. Border Router: Raspberry Pi OTBR connecting Thread mesh to internet.
  3. 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