2023-03-22 08:26:29 +00:00
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |
2021-04-02 06:49:49 +00:00
2021-09-09 13:08:57 +00:00
# OpenThread Command Line Example
2021-04-02 06:49:49 +00:00
2021-09-09 13:08:57 +00: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 06:49:49 +00:00
## How to use example
2021-09-09 13:08:57 +00:00
### Hardware Required
2021-04-02 06:49:49 +00:00
2023-07-10 11:24:19 +00:00
To run this example, a board with IEEE 802.15.4 module (for example ESP32-H2) is required.
2021-04-02 06:49:49 +00:00
### Configure the project
```
idf.py menuconfig
```
2023-09-26 04:18:08 +00: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 06:49:49 +00: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 13:08:57 +00:00
Now you'll get an OpenThread command line shell.
2021-04-02 06:49:49 +00:00
2021-09-09 13:08:57 +00:00
### Example Output
2021-04-02 06:49:49 +00:00
2021-09-09 13:08:57 +00:00
The `help` command will print all of the supported commands.
2021-04-02 06:49:49 +00:00
```bash
2021-09-09 13:08:57 +00: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 04:20:26 +00:00
To run this example, at least two ESP32-H2 boards flashed with this ot_cli example are required.
2021-09-09 13:08:57 +00:00
On the first device, run the following commands:
```bash
> factoryreset
... # the device will reboot
2021-04-02 06:49:49 +00:00
> dataset init new
Done
> dataset commit active
Done
2021-09-09 13:08:57 +00:00
> ifconfig up
Done
> thread start
Done
2021-04-02 06:49:49 +00:00
# After some seconds
> state
leader
Done
```
2021-09-09 13:08:57 +00: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 13:13:41 +00:00
```bash
2021-09-09 13:08:57 +00: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 13:13:41 +00:00
2021-09-09 13:08:57 +00:00
# Get the Active Dataset
> dataset active -x
0e080000000000010000000300001835060004001fffe00208fe7bb701f5f1125d0708fd75cbde7c6647bd0510b3914792d44f45b6c7d76eb9306eec94030f4f70656e5468726561642d35383332010258320410e35c581af5029b054fc904a24c2b27700c0402a0fff8
2021-05-25 13:13:41 +00:00
```
2021-09-09 13:08:57 +00:00
On the second device, set the active dataset from leader, and start Thread interface:
2021-05-25 13:13:41 +00:00
```bash
2021-09-09 13:08:57 +00:00
> factoryreset
... # the device will reboot
2021-05-25 13:13:41 +00:00
2021-09-09 13:08:57 +00:00
> dataset set active 0e080000000000010000000300001835060004001fffe00208fe7bb701f5f1125d0708fd75cbde7c6647bd0510b3914792d44f45b6c7d76eb9306eec94030f4f70656e5468726561642d35383332010258320410e35c581af5029b054fc904a24c2b27700c0402a0fff8
2021-05-25 13:13:41 +00:00
> ifconfig up
Done
> thread start
Done
2021-09-09 13:08:57 +00:00
# After some seconds
2021-05-25 13:13:41 +00:00
> state
router # child is also a valid state
Done
```
2021-09-09 13:08:57 +00:00
The second device has joined the Thread network as a router (or a child).
2021-05-25 13:13:41 +00:00
2022-01-11 07:36:50 +00:00
## Extension commands
2021-05-25 13:13:41 +00:00
2022-07-20 01:43:52 +00: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 13:13:41 +00:00
2022-01-11 07:36:50 +00:00
The following examples are supported by `ot_cli` :
2021-07-30 07:55:37 +00:00
2022-01-04 12:45:37 +00:00
* TCP and UDP Example
* Iperf Example
2021-07-30 07:55:37 +00:00