1# OpenThread CLI - CoAP Example
2
3The OpenThread CoAP APIs may be invoked via the OpenThread CLI.
4
5## Quick Start
6
7### Form Network
8
9Form a network with at least two devices.
10
11### Node 1
12
13On node 1, setup CoAP server with resource `test-resource`.
14
15```bash
16> coap start
17Done
18> coap resource test-resource
19Done
20```
21
22### Node 2
23
24```bash
25> coap start
26Done
27> coap get fdde:ad00:beef:0:d395:daee:a75:3964 test-resource
28Done
29coap response from [fdde:ad00:beef:0:2780:9423:166c:1aac] with payload: 30
30> coap put fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload
31Done
32coap response from [fdde:ad00:beef:0:2780:9423:166c:1aac]
33```
34
35### Result
36
37On node 1, you should see output similar to below:
38
39```bash
40coap request from [fdde:ad00:beef:0:b3:e3f6:2dcc:4b79] GET
41coap response sent
42coap request from [fdde:ad00:beef:0:b3:e3f6:2dcc:4b79] PUT with payload: 7061796c6f6164
43coap response sent
44```
45
46## Command List
47
48- [help](#help)
49- [cancel](#cancel)
50- [delete](#delete-address-uri-path-type-payload)
51- [get](#get-address-uri-path-type)
52- [observe](#observe-address-uri-path-type)
53- [parameters](#parameters)
54- [post](#post-address-uri-path-type-payload)
55- [put](#put-address-uri-path-type-payload)
56- [resource](#resource-uri-path)
57- [set](#set-new-content)
58- [start](#start)
59- [stop](#stop)
60
61## Command Details
62
63### help
64
65```bash
66> coap help
67help
68cancel
69delete
70get
71observe
72parameters
73post
74put
75resource
76set
77start
78stop
79Done
80```
81
82List the CoAP CLI commands.
83
84### cancel
85
86Request the cancellation of an existing observation subscription to a remote resource.
87
88```bash
89> coap cancel
90Done
91```
92
93### delete \<address\> \<uri-path\> \[type\] \[payload\]
94
95- address: IPv6 address of the CoAP server.
96- uri-path: URI path of the resource.
97- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
98- payload: CoAP request payload.
99
100```bash
101> coap delete fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload
102Done
103```
104
105### get \<address\> \<uri-path\> \[type\]
106
107- address: IPv6 address of the CoAP server.
108- uri-path: URI path of the resource.
109- type: "con" for Confirmable or "non-con" for Non-confirmable (default). Use "block-<block-size>" if the response should be transferred block-wise. ("block-16","block-32","block-64","block-128","block-256","block-512","block-1024")
110
111```bash
112> coap get fdde:ad00:beef:0:2780:9423:166c:1aac test-resource
113Done
114```
115
116```bash
117> coap get fdde:ad00:beef:0:2780:9423:166c:1aac test-resource block-1024
118Done
119```
120
121### observe \<address\> \<uri-path\> \[type\]
122
123This is the same a `get`, but the `Observe` parameter will be sent, set to 0 triggering a subscription request.
124
125- address: IPv6 address of the CoAP server.
126- uri-path: URI path of the resource.
127- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
128
129```bash
130> coap observe fdde:ad00:beef:0:2780:9423:166c:1aac test-resource
131Done
132```
133
134### parameters \<type\> \["default"|<ack_timeout\> <ack_random_factor_numerator\> <ack_random_factor_denominator\> <max_retransmit\>\]
135
136Sets transmission parameters for the following interactions.
137
138- type: "request" for CoAP requests and "response" for CoAP responses.
139
140If no more parameters are given, the command prints the current configuration:
141
142```bash
143> coap parameters request
144Transmission parameters for request:
145ACK_TIMEOUT=1000 ms, ACK_RANDOM_FACTOR=255/254, MAX_RETRANSMIT=2
146Done
147```
148
149If `"default"` is given, the command sets the default configuration for the transmission parameters.
150
151```bash
152> coap parameters request default
153Transmission parameters for request:
154default
155Done
156```
157
158Also, you can specify the transmission parameters in the command line:
159
160- ack_timeout (0~UINT32_MAX): RFC7252 ACK_TIMEOUT, in milliseconds.
161- ack_random_factor_numerator, ack_random_factor_denominator (0~255): RFC7252 ACK_RANDOM_FACTOR=ack_random_factor_numerator/ack_random_factor_denominator.
162- max_retransmit (0~255): RFC7252 MAX_RETRANSMIT.
163
164```bash
165> coap parameters request 1000 255 254 2
166Transmission parameters for request:
167ACK_TIMEOUT=1000 ms, ACK_RANDOM_FACTOR=255/254, MAX_RETRANSMIT=2
168Done
169```
170
171### post \<address\> \<uri-path\> \[type\] \[payload\]
172
173- address: IPv6 address of the CoAP server.
174- uri-path: URI path of the resource.
175- type: "con" for Confirmable or "non-con" for Non-confirmable (default). Use "block-<block-size>" to send blocks with random payload. ("block-16","block-32","block-64","block-128","block-256","block-512","block-1024")
176- payload: CoAP request payload. If \[type\] is "block-<block-size>", the amount of blocks to be sent can be set here.
177
178```bash
179> coap post fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload
180Done
181```
182
183```bash
184> coap post fdde:ad00:beef:0:2780:9423:166c:1aac test-resource block-1024 10
185Done
186```
187
188### put \<address\> \<uri-path\> \[type\] \[payload\]
189
190- address: IPv6 address of the CoAP server.
191- uri-path: URI path of the resource.
192- type: "con" for Confirmable or "non-con" for Non-confirmable (default). Use "block-<block-size>" to send blocks with random payload. ("block-16","block-32","block-64","block-128","block-256","block-512","block-1024")
193- payload: CoAP request payload. If \[type\] is "block-<block-size>", the amount of blocks to be sent can be set here.
194
195```bash
196> coap put fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload
197Done
198```
199
200```bash
201> coap put fdde:ad00:beef:0:2780:9423:166c:1aac test-resource block-1024 10
202Done
203```
204
205### resource \[uri-path\]
206
207Sets the URI path for the test resource.
208
209```bash
210> coap resource test-resource
211Done
212> coap resource
213test-resource
214Done
215```
216
217### set \[new-content\]
218
219Sets the content sent by the test resource. If a CoAP client is observing the resource, a notification is sent to that client.
220
221```bash
222> coap set Testing123
223Done
224```
225
226### start
227
228Starts the application coap service.
229
230```bash
231> coap start
232Done
233```
234
235### stop
236
237Stops the application coap service.
238
239```bash
240> coap stop
241Done
242```
243