libraries/OpenThread/examples/CLI/onReceive/README.md
This example demonstrates how to use the OpenThread CLI callback mechanism to capture and process CLI responses asynchronously.
The application shows how to set up a callback function that processes CLI responses line by line, allowing non-blocking CLI interaction.
| SoC | Thread | Status |
|---|---|---|
| ESP32-H2 | ✅ | Fully supported |
| ESP32-C6 | ✅ | Fully supported |
| ESP32-C5 | ✅ | Fully supported |
CONFIG_OPENTHREAD_ENABLED). This is done automatically when using the ESP32 Arduino OpenThread library.OpenThread.begin() which automatically starts a Thread network with default settings.OpenThreadCLI.onReceive()OpenThreadNo configuration is required before uploading the sketch. The example automatically starts a Thread network with default settings.
onReceive.ino sketch in the Arduino IDE.Once the sketch is running, open the Serial Monitor at a baud rate of 115200. You should see output similar to the following:
OpenThread CLI RESP===> disabled
OpenThread CLI RESP===> disabled
OpenThread CLI RESP===> detached
OpenThread CLI RESP===> child
OpenThread CLI RESP===> router
OpenThread CLI RESP===> router
...
The callback function processes each line of CLI response, showing the device state transitions from "disabled" to "detached" to "child" to "router" (or "leader").
The example demonstrates the callback-based CLI interaction pattern:
OThreadCLI.onReceive(otReceivedLine) registers a callback functionOThreadCLI.println("state") sends CLI commandsotReceivedLine() processes responses asynchronouslyThe example continuously monitors the device state:
You can modify the otReceivedLine() function to:
The onReceive example consists of the following main components:
otReceivedLine() callback function:
setup():
OpenThread.begin() (auto-start)OThreadCLI.onReceive(otReceivedLine)loop():
OThreadCLI.println("state")This example is licensed under the Apache License, Version 2.0.