xref: /aosp_15_r20/external/openthread/examples/apps/cli/README.md (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker# OpenThread CLI Example
2*cfb92d14SAndroid Build Coastguard Worker
3*cfb92d14SAndroid Build Coastguard WorkerThis example application exposes OpenThread configuration and management APIs via a simple command-line interface. The steps below take you through the minimal steps required to ping one emulated Thread device from another emulated Thread device.
4*cfb92d14SAndroid Build Coastguard Worker
5*cfb92d14SAndroid Build Coastguard Worker## 1. Build
6*cfb92d14SAndroid Build Coastguard Worker
7*cfb92d14SAndroid Build Coastguard Worker```bash
8*cfb92d14SAndroid Build Coastguard Worker$ cd <path-to-openthread>
9*cfb92d14SAndroid Build Coastguard Worker$ ./script/cmake-build simulation
10*cfb92d14SAndroid Build Coastguard Worker```
11*cfb92d14SAndroid Build Coastguard Worker
12*cfb92d14SAndroid Build Coastguard Worker## 2. Start node 1
13*cfb92d14SAndroid Build Coastguard Worker
14*cfb92d14SAndroid Build Coastguard WorkerSpawn the process:
15*cfb92d14SAndroid Build Coastguard Worker
16*cfb92d14SAndroid Build Coastguard Worker```bash
17*cfb92d14SAndroid Build Coastguard Worker$ cd <path-to-openthread>/build/simulation/examples/apps/cli
18*cfb92d14SAndroid Build Coastguard Worker$ ./ot-cli-ftd 1
19*cfb92d14SAndroid Build Coastguard Worker```
20*cfb92d14SAndroid Build Coastguard Worker
21*cfb92d14SAndroid Build Coastguard WorkerGenerate, view, and commit a new Active Operational Dataset:
22*cfb92d14SAndroid Build Coastguard Worker
23*cfb92d14SAndroid Build Coastguard Worker```bash
24*cfb92d14SAndroid Build Coastguard Worker> dataset init new
25*cfb92d14SAndroid Build Coastguard WorkerDone
26*cfb92d14SAndroid Build Coastguard Worker> dataset
27*cfb92d14SAndroid Build Coastguard WorkerActive Timestamp: 1
28*cfb92d14SAndroid Build Coastguard WorkerChannel: 13
29*cfb92d14SAndroid Build Coastguard WorkerChannel Mask: 0x07fff800
30*cfb92d14SAndroid Build Coastguard WorkerExt PAN ID: d63e8e3e495ebbc3
31*cfb92d14SAndroid Build Coastguard WorkerMesh Local Prefix: fd3d:b50b:f96d:722d::/64
32*cfb92d14SAndroid Build Coastguard WorkerNetwork Key: dfd34f0f05cad978ec4e32b0413038ff
33*cfb92d14SAndroid Build Coastguard WorkerNetwork Name: OpenThread-8f28
34*cfb92d14SAndroid Build Coastguard WorkerPAN ID: 0x8f28
35*cfb92d14SAndroid Build Coastguard WorkerPSKc: c23a76e98f1a6483639b1ac1271e2e27
36*cfb92d14SAndroid Build Coastguard WorkerSecurity Policy: 0, onrc
37*cfb92d14SAndroid Build Coastguard WorkerDone
38*cfb92d14SAndroid Build Coastguard Worker> dataset commit active
39*cfb92d14SAndroid Build Coastguard WorkerDone
40*cfb92d14SAndroid Build Coastguard Worker```
41*cfb92d14SAndroid Build Coastguard Worker
42*cfb92d14SAndroid Build Coastguard WorkerBring up the IPv6 interface:
43*cfb92d14SAndroid Build Coastguard Worker
44*cfb92d14SAndroid Build Coastguard Worker```bash
45*cfb92d14SAndroid Build Coastguard Worker> ifconfig up
46*cfb92d14SAndroid Build Coastguard WorkerDone
47*cfb92d14SAndroid Build Coastguard Worker```
48*cfb92d14SAndroid Build Coastguard Worker
49*cfb92d14SAndroid Build Coastguard WorkerStart Thread protocol operation:
50*cfb92d14SAndroid Build Coastguard Worker
51*cfb92d14SAndroid Build Coastguard Worker```bash
52*cfb92d14SAndroid Build Coastguard Worker> thread start
53*cfb92d14SAndroid Build Coastguard WorkerDone
54*cfb92d14SAndroid Build Coastguard Worker```
55*cfb92d14SAndroid Build Coastguard Worker
56*cfb92d14SAndroid Build Coastguard WorkerWait a few seconds and verify that the device has become a Thread Leader:
57*cfb92d14SAndroid Build Coastguard Worker
58*cfb92d14SAndroid Build Coastguard Worker```bash
59*cfb92d14SAndroid Build Coastguard Worker> state
60*cfb92d14SAndroid Build Coastguard Workerleader
61*cfb92d14SAndroid Build Coastguard WorkerDone
62*cfb92d14SAndroid Build Coastguard Worker```
63*cfb92d14SAndroid Build Coastguard Worker
64*cfb92d14SAndroid Build Coastguard WorkerView IPv6 addresses assigned to Node 1's Thread interface:
65*cfb92d14SAndroid Build Coastguard Worker
66*cfb92d14SAndroid Build Coastguard Worker```bash
67*cfb92d14SAndroid Build Coastguard Worker> ipaddr
68*cfb92d14SAndroid Build Coastguard Workerfd3d:b50b:f96d:722d:0:ff:fe00:fc00
69*cfb92d14SAndroid Build Coastguard Workerfd3d:b50b:f96d:722d:0:ff:fe00:c00
70*cfb92d14SAndroid Build Coastguard Workerfd3d:b50b:f96d:722d:7a73:bff6:9093:9117
71*cfb92d14SAndroid Build Coastguard Workerfe80:0:0:0:6c41:9001:f3d6:4148
72*cfb92d14SAndroid Build Coastguard WorkerDone
73*cfb92d14SAndroid Build Coastguard Worker```
74*cfb92d14SAndroid Build Coastguard Worker
75*cfb92d14SAndroid Build Coastguard Worker## 2. Start node 2
76*cfb92d14SAndroid Build Coastguard Worker
77*cfb92d14SAndroid Build Coastguard WorkerSpawn the process:
78*cfb92d14SAndroid Build Coastguard Worker
79*cfb92d14SAndroid Build Coastguard Worker```bash
80*cfb92d14SAndroid Build Coastguard Worker$ cd <path-to-openthread>/build/simulation/examples/apps/cli
81*cfb92d14SAndroid Build Coastguard Worker$ ./ot-cli-ftd 2
82*cfb92d14SAndroid Build Coastguard Worker```
83*cfb92d14SAndroid Build Coastguard Worker
84*cfb92d14SAndroid Build Coastguard WorkerConfigure Thread Network Key from Node 1's Active Operational Dataset:
85*cfb92d14SAndroid Build Coastguard Worker
86*cfb92d14SAndroid Build Coastguard Worker```bash
87*cfb92d14SAndroid Build Coastguard Worker> dataset networkkey dfd34f0f05cad978ec4e32b0413038ff
88*cfb92d14SAndroid Build Coastguard WorkerDone
89*cfb92d14SAndroid Build Coastguard Worker> dataset commit active
90*cfb92d14SAndroid Build Coastguard WorkerDone
91*cfb92d14SAndroid Build Coastguard Worker```
92*cfb92d14SAndroid Build Coastguard Worker
93*cfb92d14SAndroid Build Coastguard WorkerBring up the IPv6 interface:
94*cfb92d14SAndroid Build Coastguard Worker
95*cfb92d14SAndroid Build Coastguard Worker```bash
96*cfb92d14SAndroid Build Coastguard Worker> ifconfig up
97*cfb92d14SAndroid Build Coastguard WorkerDone
98*cfb92d14SAndroid Build Coastguard Worker```
99*cfb92d14SAndroid Build Coastguard Worker
100*cfb92d14SAndroid Build Coastguard WorkerStart Thread protocol operation:
101*cfb92d14SAndroid Build Coastguard Worker
102*cfb92d14SAndroid Build Coastguard Worker```bash
103*cfb92d14SAndroid Build Coastguard Worker> thread start
104*cfb92d14SAndroid Build Coastguard WorkerDone
105*cfb92d14SAndroid Build Coastguard Worker```
106*cfb92d14SAndroid Build Coastguard Worker
107*cfb92d14SAndroid Build Coastguard WorkerWait a few seconds and verify that the device has become a Thread Child or Router:
108*cfb92d14SAndroid Build Coastguard Worker
109*cfb92d14SAndroid Build Coastguard Worker```bash
110*cfb92d14SAndroid Build Coastguard Worker> state
111*cfb92d14SAndroid Build Coastguard Workerchild
112*cfb92d14SAndroid Build Coastguard WorkerDone
113*cfb92d14SAndroid Build Coastguard Worker```
114*cfb92d14SAndroid Build Coastguard Worker
115*cfb92d14SAndroid Build Coastguard Worker## 3. Ping Node 1 from Node 2
116*cfb92d14SAndroid Build Coastguard Worker
117*cfb92d14SAndroid Build Coastguard Worker```bash
118*cfb92d14SAndroid Build Coastguard Worker> ping fd3d:b50b:f96d:722d:7a73:bff6:9093:9117
119*cfb92d14SAndroid Build Coastguard Worker16 bytes from fd3d:b50b:f96d:722d:558:f56b:d688:799: icmp_seq=1 hlim=64 time=24ms
120*cfb92d14SAndroid Build Coastguard Worker```
121*cfb92d14SAndroid Build Coastguard Worker
122*cfb92d14SAndroid Build Coastguard Worker## 4. Explore More
123*cfb92d14SAndroid Build Coastguard Worker
124*cfb92d14SAndroid Build Coastguard WorkerSee the [OpenThread CLI Reference README.md](../../../src/cli/README.md) to explore more.
125