Old Macdonald - Decentralised Controlled Environment Agriculture System Help

ESP OpenThread CLI

This section describes how to build and run the OpenThread CLI example project from the ESP-IDF. It can be used to test and debug the OpenThread stack on ESP32 series SoCs.

Prerequisites:

Build and Run

Step 1: Prepare the Environment

get_idf cd $IDF_PATH/examples/openthread/ot_cli

Step 2: Set target

The following command sets the target device to ESP32-H2:

idf.py set-target esp32h2

Step 3 (Optional): Configure Device

The example can run with the default configuration. idf.py menuconfig can be used for customized settings:

  • Enabling Joiner Role: Component Config → OpenThread → Thread Core Features → Enable Joiner

Step 4: Connect to Computer

Connect the ESP32-H2-DevKitM-1 to the computer using a USB cable.

Step 5: Build and Flash

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

Usage

Joining Thread Network

A Thread device can join the network using either a minimal dataset (providing only the Network Key) or a complete Active Operational Dataset.

Example 1: Joining with Minimal Provisioning (Network Key Only)

The device is initially provisioned with only the Network Key. After joining, the device synchronizes with the network and automatically receives the complete Active Operational Dataset.

dataset networkkey 00112233445566778899aabbccddeeff dataset commit active ifconfig up thread start

Display the full Active Operational Dataset:

dataset active

Example 2: Joining with the Full Active Operational Dataset

In this method, all network parameters (such as PAN ID, channel, Mesh-Local Prefix, etc.) are provisioned upfront. The device is configured with the complete dataset before starting the Thread interface.

dataset set active 0e080000000000010000000300001835060004001fffe00208fe7bb701f5f1125d0708fd75cbde7c6647bd0510b3914792d44f45b6c7d76eb9306eec94030f4f70656e5468726561642d35383332010258320410e35c581af5029b054fc904a24c2b27700c0402a0fff8 ifconfig up thread start

Commissioning

Joiner device:

  • Get the factory-assigned IEEE EUI-64 address (e.g., 744dbdfffe63f5c8).

    eui64
  • Bring the IPv6 interface up, enable the Thread Joiner role, and start the Thread protocol:

    ifconfig up joiner start J00MMM thread start

Commissioner device:

  • Start the Commissioner role:

    commissioner start
  • Add a joiner entry:

    commissioner joiner add <eui64|discerner> <pksd>

    Example:

    commissioner joiner add 744dbdfffe63f5c8 J00MMM or commissioner joiner add * J00MMM
  • Display all Joiner entries in table format:

    commissioner joiner table

The Joiner device receives the Network Key when joining the network.

Retrieving Information

The command router table prints a list of routers in a table format. Each router is identified by its Extended MAC.

The command extaddr returns the Extended MAC address of a device.

The joiner id command returns the Joiner ID used for commissioning.

Sending UDP packets

Running UDP Server:

udpsockserver open udpsockserver bind 12345 udpsockserver status

Sending a UDP packet and closing the server:

udpsockserver send fdf9:2548:ce39:efbb:9612:c4a0:477b:349a 12346 hello udpsockserver close

Running UDP Client:

udpsockclient open # or udpsockclient open <port>, e.g., udpsockclient open 12345 udpsockclient status

Sending a UDP packet and closing the client:

udpsockclient send fdf9:2548:ce39:efbb:79b9:4ac4:f686:8fc9 12346 hello udpsockclient close

Scanning and Discovering

The scan command performs IEEE 802.15.4 scan to find nearby devices. The discover command performs an MLE Discovery operation to find Thread networks nearby.

Thread Discover
Thread Scan

References

ESP Thread Sniffer:

  • https://docs.espressif.com/projects/esp-zigbee-sdk/en/latest/esp32h2/developing.html#sniffer-and-wireshark

  • https://openthread.io/guides/pyspinel/sniffer

  • https://github.com/espressif/esp-idf/blob/master/examples/openthread/ot_rcp/README.md

Last modified: 26 March 2025