Thread Interface
Overview
This section outlines the development of the Thread Interface component, which provides the features and functions to create Thread networks and commission devices to join them.
This component is part of the Orchestrator firmware.
Pre-requisites:
The steps in Project Bootstrap section are completed.
System Initialization is completed.
Development
Step 1: Create Component
The command below creates a new component named thread_interface inside the components directory.
The CONFIG_OPENTHREAD_ENABLE configuration option has to be set to y in the sdkconfig.defaults file in order to enable the OpenThread component.
Step 2: Change Source File Extension
Change the file extension of the thread_interface.c file to thread_interface.cpp.
Step 3: Manage Thread Network
The thread_interface.h file declares functions for managing the Thread network:
Initializing the Thread Interface
The initialization process involves the following steps:
Configure event handlers to manage Thread network events.
Set up the Event VFS, a lightweight mechanism that represents events as file descriptors, similar to Linux's eventfd. This allows tasks to signal and wait for events. The Event VFS is part of the broader VFS component, which provides a unified interface for various file systems.
Creating a Dedicated FreeRTOS Task, declared in
thread_task.h, using thexTaskCreatefunction. This task:Initializes a new OpenThread network interface using
esp_netif.Initializes the OpenThread stack and attaches the network interface.
Sets up the OpenThread CLI
Starts OpenThread.
Shutting Down the Thread Interface
Stops the OpenThread stack.
Deletes the OpenThread task using
vTaskDelete.Unregisters the Event VFS.
Cleans up allocated semaphores and network interfaces.
Retrieving and Setting the Operational Dataset
Getting the Device’s Thread Role:
Disabled – The device is not participating in the Thread network.
Detached – The device is trying to connect to a Thread network but is not yet attached.
Child – The device is connected to a Thread network but does not route traffic.
Router – The device is forwarding messages for other Thread nodes.
Leader – The device is managing the Thread network and ensuring proper operation.
OpenThread Configuration
Create a file that defines default configurations for OpenThread on ESP32-C6:
The code below sets up the network interface for Thread communication and configures the radio to use native mode. It also manages storage and task queues through the port configuration.
References
OpenThread SDK:
Android SDK