Understanding Thread Network Formation- STm32WB

Introduction

In this episode, we dive deeper into how Thread nodes discover, form, and join a mesh network. We’ll break down the technical sequence of events. We will cover the commands used during commissioning. We will also explore how OpenThread manages security and role selection during network formation.

Network Formation: The Leader’s Role

When a Thread device powers on and doesn’t detect an existing network, it attempts to form a new one. If it’s eligible (e.g., has sufficient link quality and memory), it will elect itself as the Leader.

  • otThreadSetEnabled(instance, true) – Enables the Thread protocol on the device.
  • The device listens on specific IEEE 802.15.4 channels, scans for existing networks, and initiates network formation if none are found.
  • It assigns itself as the Leader and starts sending advertisements to allow other nodes to join.

Commissioning: Secure Joining Process

Joining a Thread network is not as simple as just listening to packets; it’s a secured process called commissioning.

  1. Discovery Request: Joiner sends a beacon request with its capabilities.
  2. Commissioner Response: The Commissioner authenticates the Joiner via PSKd (Pre-Shared Key for Device).
  3. DTLS Session: A secure DTLS handshake occurs over the Joiner Entrust mechanism.
  4. Network Credentials: Upon success, the Joiner receives network parameters (e.g., PAN ID, channel, network key).

On OpenThread, the Commissioner is started via:

otCommissionerStart(instance, commissionerCallback, context);

Joining from Application Side

To make a device act as a Joiner, you must use:


otJoinerStart(instance, pskd, provisioningUrl, vendorName, vendorModel,
              vendorSwVersion, vendorData, joinerCallback, context);

This function sets up the Joiner to initiate discovery and pairing with an existing Commissioner. After joining, it becomes an End Device, Router, or even a Leader, depending on the network state and configuration.

Role Selection Logic

Once part of the network, OpenThread dynamically adjusts the device’s role:

  • Child/End Device: Joins the mesh and forwards packets via a parent router.
  • Router: If network demands increase (e.g., many End Devices), it may upgrade itself.
  • Leader: Elected from existing routers based on a deterministic algorithm.

This behavior is managed automatically but can be queried via:
otThreadGetDeviceRole() and monitored using otSetStateChangedCallback().

Security Handling

Thread protocol enforces strong network security:

  • All traffic is encrypted using AES-128 CCM based on a network-wide key.
  • Devices must authenticate via PSKd before receiving this key.
  • Key rotation and nonce replay protection are handled internally by OpenThread.

Conclusion

Thread is not just a mesh—it’s a secure, self-healing, self-forming network with built-in device commissioning. Understanding how devices join and establish trust is critical for building reliable IoT systems. In the next episode, we’ll dive into CoAP communication between Thread nodes using STM32WB.

Leave a comment