Introduction
Welcome to the OpenThread Application Framework documentation! The OpenThread Application Framework is a comprehensive middleware solution for building Thread-based IoT devices. It provides a clean abstraction layer between OpenThread/CoAP protocols and device-specific hardware implementations, enabling rapid development of smart home devices such as buttons, lights, switches, and sensors. Key Features:
- ✅ Device abstraction layer with unified API
- ✅ Automatic device discovery and pairing
- ✅ CoAP application layer with simplified URI management
- ✅ Hardware-independent device driver interface
- ✅ Event-driven callback architecture
- ✅ Device name grouping for organized pairing
- ✅ Real-time status updates via CoAP Observe
- ✅ Configurable pairing rules and device filtering
- ✅ Factory reset capability
- ✅ Multi-platform support (STM32, ESP32)
Framework Architecture
The framework follows a layered architecture that separates concerns and provides clear abstraction boundaries:
┌────────────────────────────────────────────────────────────┐
│ Application/Device Layer │
│ (Button Device, Light Device, Sensor Device, etc.) │
│ - Device-specific logic │
│ - User interaction handling │
│ - Device state management │
├────────────────────────────────────────────────────────────┤
│ OpenThread Application Framework │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Device Management API │ │
│ │ - Device discovery and pairing │ │
│ │ - Device name groups │ │
│ │ - Pairing rules and filtering │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ CoAP Application API │ │
│ │ - URI endpoint registration │ │
│ │ - CoAP Observe (subscription/notification) │ │
│ │ - Resource management │ │
│ ├──────────────────────────────────────────────────────┤ │
│ │ Device Driver Interface │ │
│ │ - Callback-based event handling │ │
│ │ - Task management │ │
│ │ - Device lifecycle management │ │
│ └──────────────────────────────────────────────────────┘ │
├────────────────────────────────────────────────────────────┤
│ Protocol Stack (OpenThread + CoAP) │
│ - Thread mesh networking │
│ - IPv6 addressing │
│ - CoAP protocol │
│ - Network commissioning │
├────────────────────────────────────────────────────────────┤
│ Hardware Abstraction Layer (HAL) │
│ - GPIO drivers (buttons, LEDs) │
│ - Timer drivers │
│ - Peripheral drivers (SPI, I2C, UART) │
│ - Platform-specific implementations │
└────────────────────────────────────────────────────────────┘
Application Flow
The application is built around the OpenThread Application Framework and the device driver API defined in main API for OpenThread hardware application.
High-level runtime flow:
- OpenThread APP init:
- Configure Thread stack and commissioning modules
- Initialize driver API instance via ot_app_drv_getInstance()
- Set TLV data, MAC address, device name and register callbacks
- Initialize modules: Pairing, COAP, SRP client, CLI (platform dependent)
- Enter idle / listen state:
- Listen for OpenThread events (DNS, COAP messages, device state changes)
- DNS / service handling:
- If DNS server is online, add services to DNS server and periodically check leases
- Browse services and update pairing state if RLOC changes
- Device pairing and observer registration:
- Process responses from OpenThread and add URI indexes to the device list
- Register observers for paired devices and subscribed URIs
- COAP message processing:
- Handle COAP messages from DNS and direct device URIs
- Route requests to:
- pairing_services URIs,
- subscribed_uris,
- device-specific URIs (device API)
- For paired devices call:
- obs_subscribedUri_clb() for URI updates
- obs_pairedDevice_clb() when a new device is successfully paired
- Periodic device task:
This flow ensures that hardware devices are discovered, paired, registered in DNS, and controlled via COAP URIs using a unified driver API.
Quick Start
This section shows how to configure and run a simple OpenThread setup with:
- Controller device: Button device (ad_button)
- Target device: RGB light device (ad_light + ad_light_control + WS2812B)
1. Hardware Setup (example ESP32-C6):
- Connect 3 momentary buttons to GPIOs, with pull‑ups enabled:
- BUTTON_1 → GPIO 3
- BUTTON_2 → GPIO 9
- BUTTON_3 → GPIO 15
- See also
- Button Device Button Device
- Connect RGB LED strip (WS2812B) data line to a single GPIO used by the RMT driver:
- WS2812B DIN → GPIO 8
- See also
- Light Device Light Device
2. Software Integration – Light Device (target, based on main.c): The main application initializes the light device, OpenThread framework, WS2812B driver and timers
void app_main(void)
{
xTim_Init();
while (1)
{
vTaskDelay(pdMS_TO_TICKS(1));
}
}
void ad_light_init(char *deviceNameGroup)
Initialize the RGB light device and register it in the framework.
Definition ad_light.c:114
int8_t otapp_init(void)
Main initialization of the OpenThread Application Framework. Initializes the driver instance,...
Definition ot_app.c:231
void ot_app_drv_task(void)
Definition ot_app_drv.c:67
@ FX_MODE_COLOR_WIPE
8: Progressive color fill
Definition ws2812b_fx.h:208
void WS2812BFX_Callback(void)
Definition ws2812b_fx.c:334
FX_STATUS WS2812BFX_Start(uint16_t Segment)
Definition ws2812b_fx.c:516
FX_STATUS WS2812BFX_SetMode(uint16_t Segment, fx_mode Mode)
Definition ws2812b_fx.c:360
FX_STATUS WS2812BFX_Init(const ws2812b_drv_t *drv, uint16_t Segments)
Definition ws2812b_fx.c:215
FX_STATUS WS2812BFX_SetSpeed(uint16_t Segment, uint16_t Speed)
Definition ws2812b_fx.c:737
void WS2812BFX_SetColorRGB(uint8_t id, uint8_t r, uint8_t g, uint8_t b)
Definition ws2812b_fx.c:563
const ws2812b_drv_t * ws2812b_if_getDrvRMT(void)
Get RMT driver interface.
Definition ws2812b_drv_RMT.c:66
void ws2812b_if_init(void)
Initialize RMT peripheral for WS2812B control.
Definition ws2812b_drv_RMT.c:166
3. Software Integration – Button Device (controller): On another node, use the button device as controller
void app_main(void)
{
xTim_Init();
while (1)
{
vTaskDelay(pdMS_TO_TICKS(1));
}
}
4. Pair and Control Devices:
- See also
- Device API (ot_app_drv.h) - main API for OpenThread hardware application
-
Button Device for button device implementation
-
Light Device for light device implementation
Device Abstraction
The framework provides a unified API for creating different device types:
- Button devices - Control switches with single/double/long-press
- Light devices - Dimmable and color-changing lights
- Sensor devices - Temperature, humidity, motion sensors
- Custom devices - Extend framework for new device types
Automatic Device Pairing
Built-in discovery and pairing mechanisms:
- Device discovery - Automatic detection of OpenThread devices
- Device name groups - Logical grouping for controlled pairing
- Pairing rules - Configurable device type filtering
- Persistent storage - NVS-based pairing data persistence
CoAP Application API
Simplified CoAP resource management:
- URI registration - Easy endpoint definition
- CoAP Observe - Subscribe to device state changes
- Request handlers - GET/POST/PUT method support
- Response builders - Simplified payload creation
Hardware Abstraction
Clean separation between application and hardware:
- Driver interface - Platform-independent API
- Callback system - Event-driven architecture
- Multi-platform - ESP32, STM32, portable to others
- Hardware libraries - OneButton, WS2812B, timers, etc.
Device Name Grouping
The framework supports device name groups for organized pairing and network segmentation. What is a Device Name Group?
- A string identifier (max 9 characters) that groups related devices
- Enables pairing only between devices in the same group
- Prevents accidental pairing across different rooms or zones Common Grouping Strategies: Room-Based Grouping: Function-Based Grouping: Building-Based Grouping:
- Note
- Both controller and target device must have matching name groups to pair
- See also
- device_naming for detailed device name group guide
Framework Modules
Core & Infrastructure
CoAP Communication Stack
- CoAP Server Engine – Unified interface for sending responses (ACK/DATA) and handling UDP traffic.
- Resource Handlers – Application-specific URI handlers for hardware control and pairing services.
- Observe Registry – Server-side registry managing remote subscribers and asynchronous notifications.
Discovery & Network Identity
- Device Naming – Unique hostname generation and group-based filtering for organized pairing.
- SRP Client – Automated service registration (Advertising) for device discoverability.
- DNS Discovery – Active scanning (Browsing) and hostname resolution for finding remote services.
- Dataset Management – Storage and application of operational network credentials.
Pairing & Hardware Abstraction
- Device Pairing – Rule-based pairing logic, trusted device list management, and capability exchange.
- Device Driver Interface – Unified singleton API bridging network logic and physical hardware.
Platform Porting Layer
- RTOS Port – Unified inclusion of FreeRTOS headers for multi-platform compatibility.
- OpenThread Port – Abstraction for OpenThread stack instance retrieval.
- NVS Storage Port – Abstraction layer for persistent storage (Flash/EEPROM).
see more: - OTApp modules details
Device Implementations
Hardware Libraries
- Utility Libraries - OneButton, Software Timers, SPIFFS, WS2812B
- Hardware Drivers - GPIO, timers, peripheral drivers
Button Functions (Example Device)
Each button supports multiple interaction types:
| Button Action | Function | Example Use Case |
| Single-click | Toggle on/off | Turn light on or off |
| Double-click | Change mode/color | Cycle through light colors |
| Long-press | Continuous adjustment | Dim or brighten light |
Flexible Pairing Rules
Three predefined pairing rule sets:
- Custom Rules - Allow only specific device types (default: lighting devices)
- Allow All - Pair with any OpenThread device
- Block All - Disable pairing (security/maintenance mode)
CoAP Integration
Example device endpoints:
- btn/state - Button state queries and notifications
- light/state - Light on/off state
- light/brightness - Brightness control
- light/color - RGB color control All endpoints support CoAP Observe for real-time updates.
Platform Support
The framework provides multi-platform support through compile-time configuration:
| Platform | Microcontroller | SDK/HAL | Status |
| ESP32 | ESP32-C6 | ESP-IDF | ✅ Active |
| STM32 | STM32 series | STM32 HAL | ⏳ In progress |
| Custom | Any | User-defined | 🔧 Portable |
Documentation Pages
- Getting Started Guide
Step-by-step guide: configuring the ESP-IDF environment, building a project for various roles (Border Router, Control Panel, Controller) and the first run of hardware examples.
- Architecture and Design Patterns
Detailed technical documentation describing the framework architecture, design patterns used (including Singleton, Observer, Facade) and RTOS techniques (queues, mutexes) and driver structures.
- Device Name Group Guide
- Platform Setup Instructions
- Configuration Guide
- API Reference
- Code Examples
Additional Resources
Unit Tests
The OpenThread Application Framework is covered by a comprehensive set of unit tests that verify core functionality of pairing, URI handling, device names, memory management, and RTOS integration.
Available test modules:
The tests are designed to run on the host using the UNITY framework, fff mocking framework, and mocked OpenThread / platform APIs. They serve as executable documentation for the behavior of the core modules.
- See also
- ot_app_pair.h for pairing data structures and APIs
-
ot_app_coap_uri_obs.h for URI observe management
-
ot_app_buffer.h for shared buffer safety mechanisms
-
ot_app_drv.h for driver API used by the tests
Author & License
- Author
- Jan Łukaszewicz (plhar.nosp@m.eo@g.nosp@m.mail..nosp@m.com)
- Copyright
- © 2025 MIT LICENCE
- Note
- This documentation was generated using Doxygen