Old Macdonald - Decentralised Controlled Environment Agriculture System Help

ESP Basic Thread Border Router

Overview

The ESP Basic Thread Border Router example from ESP_IDF demonstrates how to build firmware for a basic Thread Border Router device running on Espressif's hardware.

The firmware configures the OpenThread platform using default radio, host, and port settings. Optionally, it enables external coexistence and sets up mDNS (with the hostname "esp-ot-br"), along with OTA and web server support if enabled. Finally, it launches the Border Router.

Build and Run

This section demonstrates how to build and run the ESP Basic Thread Border Router example.

Prerequisites:

ESP Thread Border Router/Zigbee Gateway

Step 1: Build the RCP Image

get_idf cd $IDF_PATH/examples/openthread/ot_rcp/ idf.py set-target esp32h2 # Select the ESP32-H2. Skipping this step would result in a build error. idf.py build

The firmware does not need to be manually flashed onto the device. It will be integrated into the Border Router firmware and automatically installed onto the ESP32-H2 chip during the first boot-up. idf.py menuconfig can be used for customized settings.

Step 2: Clone Espressif Thread Border Router SDK

This project uses Espressif Thread Border Router SDK locked to commit cf3a09f.

cd ~/esp git clone --recursive https://github.com/espressif/esp-thread-br.git cd ~/esp/esp-thread-br/ git checkout cf3a09f5f44991a4e65b2d1c5113637e1d086b68 cd ~/esp/esp-thread-br/examples/basic_thread_border_router

Step 3: Configure the Device (Optional)

This section describes how to configure the device using idf.py menuconfig. This step is optional because the device can be configured using the OpenThread CLI after flashing the firmware.

The default configuration in sdkconfig.default file is designed to work out of the box on the ESP Thread Border Router board with ESP32-S3 as the default SoC target. For other SoCs, the target must be configured using idf.py set-target <chip_name>.

The command below opens the configuration menu:

idf.py menuconfig

Enable automatic start mode and the Web GUI:

  • ESP Thread Border Router Example → Enable the automatic start mode in Thread Border

In automatic start mode, the device first attempts to use the Wi-Fi SSID and password stored in NVS ( Non-Volatile Storage). If no Wi-Fi credentials are found in NVS, it uses EXAMPLE_WIFI_SSID and EXAMPLE_WIFI_PASSWORD, retrieved from the following configuration options:

  • Example Connection Configuration → WiFi SSID

  • Example Connection Configuration → WiFi Password

Additionally, Thread dataset can be configured:

Component config → OpenThread → Thread Core Features → Thread Operational Dataset

Thread Border Router Dataset

Step 4: Connect the ESP Thread Border Router Board

Use USB2 (ESP32-S3) on the ESP Thread Border Router Board to connect the board to the computer. Only the ESP32-S3 ( main SoC) port needs to be connected. The main SoC automatically programs the Thread co-processor.

Step 5: Build and Flash

idf.py build idf.py -p <PORT> flash monitor

OpenThread CLI

This section demonstrates how to use the OpenThread CLI on the ESP Thread Border Router.

OpenThread CLI is enabled in the ESP OpenThread component by default. It can also be enabled/disabled using the idf.py menuconfig command:

  • Component config → OpenThread → Thread Console → Enable OpenThread Command-Line Interface

The ESP Thread Border Router project extends the standard OpenThread CLI by including the OpenThread Extension Commands component with additional commands demonstrated below, such as Wi-Fi management and IP address printing.

Wi-Fi Management

Connect the ESP Thread Border Router to a Wi-Fi network:

wifi connect -s <SSID> -p <PASSWORD>

Disconnect the ESP Thread Border Router from the Wi-Fi network:

wifi disconnect

Print the current Wi-Fi network state:

wifi state

IP Addresses and Network Interfaces

Print all the IP address on each interface of lwIP of the Thread Border Router:

ip print
Print IPs

The output lists network interfaces (netif):

If the Thread Border Router is connected to a Wi-Fi network, we can ping it from another device. The following commands should be run on a Linux machine to find the name of the Wi-Fi network interfaces and then use it to ping the Thread Border Router:

ip addr ping6 -I <INTERFACE> <DEVICE_IP> ping6 -I wlo1 fe80::aaaa:0000:0000:0000 ping6 -I wlo1 2604::aaaa:0000:0000:0000
Ping

Forming Thread network

The following commands form a Thread network:

  1. Optional. Delete any previous settings stored on non-volatile memory, and then trigger a platform reset:

    factoryreset
  2. Initialize a new dataset:

    dataset init new
  3. Commit the new Operational Dataset buffer to Active Operational Dataset:

    dataset commit active
  4. Enable IPv6 communication:

    ifconfig up
  5. Enable Thread interface

    thread start
  6. Show the Active Operational Dataset. The optional -x argument prints it as hex-encoded TLVs:

    dataset active -x
    Active Operational Dataset

    The ip print command now shows the Thread interface with the IPv6 address:

    Ping

Managing Border Routing Manager

The Border Routing Manager starts automatically after enabling the Thread interface. The br command can be used to manage the Border Routing Manager.

Print the current state of Border Routing Manager:

br state

Initializes the Border Routing Manager:

br init <infrastructure-network-index> <is-running>

Enables the Border Routing Manager:

br enable

Information Commands

The platform command prints the current platform. The version and rcp version print the OpenThread version and the radio version respectively.

RESTful API and Web GUI

The ESP Thread Border Router provides a RESTful API and Web GUI for managing the Thread Border Router. It is disabled by default and can be enabled using idf.py menuconfig:

  • ESP Thread Border Router Example → Enable the web server in Thread Border Router

Web GUI Access

The Web GUI can be accessed using the IP address of the Thread Border Router:

http://<DEVICE_IP>/index.html

The Web GUI can be accessed using the IPv4 address assigned by the Wi-Fi router or the device's IPv6 Global Unicast Address (see ip print in extension-commands). IPv4 is only accessible within the local network unless port forwarding is configured on the router. IPv6 can be accessed externally if a firewall rule is added on the router.

RESTful API Client Library Generation

The API is documented using the OpenAPI specification in the openapi.yaml file. OpenAPI Generator can be used to generate a client library.

The following commands should be run on a Linux machine with installed Docker and Node.js to generate a TypeScript client library for the ESP-Thread Border Router server:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/openapi.yaml -g typescript-fetch -o /local/out/typescript-fetch sudo chown -R $USER:$USER out/ npm install --safe-dev typescript

References

Last modified: 24 March 2025