2024-07-31 05:22:06 -04:00
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- | -------- |
2021-04-02 02:49:49 -04:00
2021-09-09 09:08:57 -04:00
# OpenThread Command Line Example
2021-04-02 02:49:49 -04:00
2021-09-09 09:08:57 -04:00
This example demonstrates an [OpenThread CLI ](https://github.com/openthread/openthread/blob/master/src/cli/README.md ), with some additional features such as TCP, UDP and Iperf.
2021-04-02 02:49:49 -04:00
## How to use example
2021-09-09 09:08:57 -04:00
### Hardware Required
2021-04-02 02:49:49 -04:00
2023-07-10 07:24:19 -04:00
To run this example, a board with IEEE 802.15.4 module (for example ESP32-H2) is required.
2021-04-02 02:49:49 -04:00
### Configure the project
```
idf.py menuconfig
```
2023-09-26 00:18:08 -04:00
The example can run with the default configuration. OpenThread Command Line is enabled with UART as the default interface. Additionally, USB JTAG is also supported and can be activated through the menuconfig:
```
Component config → ESP System Settings → Channel for console output → USB Serial/JTAG Controller
```
2021-04-02 02:49:49 -04:00
### Build, Flash, and Run
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT build flash monitor
```
2021-09-09 09:08:57 -04:00
Now you'll get an OpenThread command line shell.
2021-04-02 02:49:49 -04:00
2021-09-09 09:08:57 -04:00
### Example Output
2021-04-02 02:49:49 -04:00
2021-09-09 09:08:57 -04:00
The `help` command will print all of the supported commands.
2021-04-02 02:49:49 -04:00
```bash
2021-09-09 09:08:57 -04:00
> help
I(7058) OPENTHREAD:[INFO]-CLI-----: execute command: help
bbr
bufferinfo
ccathreshold
channel
child
childip
childmax
childsupervision
childtimeout
coap
contextreusedelay
counters
dataset
delaytimermin
diag
discover
dns
domainname
eidcache
eui64
extaddr
extpanid
factoryreset
...
```
## Set Up Network
2023-04-07 00:20:26 -04:00
To run this example, at least two ESP32-H2 boards flashed with this ot_cli example are required.
2021-09-09 09:08:57 -04:00
On the first device, run the following commands:
```bash
> factoryreset
... # the device will reboot
2021-04-02 02:49:49 -04:00
> dataset init new
Done
> dataset commit active
Done
2021-09-09 09:08:57 -04:00
> ifconfig up
Done
> thread start
Done
2021-04-02 02:49:49 -04:00
# After some seconds
> state
leader
Done
```
2021-09-09 09:08:57 -04:00
Now the first device has formed a Thread network as a leader. Get some information which will be used in next steps:
2021-05-25 09:13:41 -04:00
```bash
2021-09-09 09:08:57 -04:00
> ipaddr
fdde:ad00:beef:0:0:ff:fe00:fc00
fdde:ad00:beef:0:0:ff:fe00:8000
fdde:ad00:beef:0:a7c6:6311:9c8c:271b
fe80:0:0:0:5c27:a723:7115:c8f8
2021-05-25 09:13:41 -04:00
2021-09-09 09:08:57 -04:00
# Get the Active Dataset
> dataset active -x
0e080000000000010000000300001835060004001fffe00208fe7bb701f5f1125d0708fd75cbde7c6647bd0510b3914792d44f45b6c7d76eb9306eec94030f4f70656e5468726561642d35383332010258320410e35c581af5029b054fc904a24c2b27700c0402a0fff8
2021-05-25 09:13:41 -04:00
```
2021-09-09 09:08:57 -04:00
On the second device, set the active dataset from leader, and start Thread interface:
2021-05-25 09:13:41 -04:00
```bash
2021-09-09 09:08:57 -04:00
> factoryreset
... # the device will reboot
2021-05-25 09:13:41 -04:00
2021-09-09 09:08:57 -04:00
> dataset set active 0e080000000000010000000300001835060004001fffe00208fe7bb701f5f1125d0708fd75cbde7c6647bd0510b3914792d44f45b6c7d76eb9306eec94030f4f70656e5468726561642d35383332010258320410e35c581af5029b054fc904a24c2b27700c0402a0fff8
2021-05-25 09:13:41 -04:00
> ifconfig up
Done
> thread start
Done
2021-09-09 09:08:57 -04:00
# After some seconds
2021-05-25 09:13:41 -04:00
> state
router # child is also a valid state
Done
```
2021-09-09 09:08:57 -04:00
The second device has joined the Thread network as a router (or a child).
2021-05-25 09:13:41 -04:00
2022-01-11 02:36:50 -05:00
## Extension commands
2021-05-25 09:13:41 -04:00
2022-07-19 21:43:52 -04:00
You can refer to the [extension command ](https://github.com/espressif/esp-thread-br/blob/main/components/esp_ot_cli_extension/README.md ) about the extension commands.
2021-05-25 09:13:41 -04:00
2022-01-11 02:36:50 -05:00
The following examples are supported by `ot_cli` :
2021-07-30 03:55:37 -04:00
2022-01-04 07:45:37 -05:00
* TCP and UDP Example
* Iperf Example
2021-07-30 03:55:37 -04:00