The OpenThread CoAP APIs may be invoked via the OpenThread CLI.
Use the COAP=1
build switch to enable CoAP API support.
> ./bootstrap > make -f examples/Makefile-simulation COAP=1
Form a network with at least two devices.
On node 1, setup CoAP server with resource test-resource
.
> coap start Done > coap resource test-resource Done
> coap start Done > coap get fdde:ad00:beef:0:d395:daee:a75:3964 test-resource Done coap response from [fdde:ad00:beef:0:2780:9423:166c:1aac] with payload: 30 > coap put fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload Done coap response from [fdde:ad00:beef:0:2780:9423:166c:1aac]
On node 1, you should see output similar to below:
coap request from [fdde:ad00:beef:0:b3:e3f6:2dcc:4b79] GET coap response sent coap request from [fdde:ad00:beef:0:b3:e3f6:2dcc:4b79] PUT with payload: 7061796c6f6164 coap response sent
> coap help help cancel delete get observe parameters post put resource set start stop Done
List the CoAP CLI commands.
Request the cancellation of an existing observation subscription to a remote resource.
> coap cancel Done
> coap delete fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload Done
> coap get fdde:ad00:beef:0:2780:9423:166c:1aac test-resource Done
This is the same a get
, but the Observe
parameter will be sent, set to 0 triggering a subscription request.
> coap observe fdde:ad00:beef:0:2780:9423:166c:1aac test-resource Done
Sets transmission parameters for the following interactions.
If no more parameters are given, the command prints the current configuration:
> coap parameters request Transmission parameters for request: ACK_TIMEOUT=1000 ms, ACK_RANDOM_FACTOR=255/254, MAX_RETRANSMIT=2 Done
If "default"
is given, the command sets the default configuration for the transmission parameters.
> coap parameters request default Transmission parameters for request: default Done
Also, you can specify the transmission parameters in the command line:
> coap parameters request 1000 255 254 2 Transmission parameters for request: ACK_TIMEOUT=1000 ms, ACK_RANDOM_FACTOR=255/254, MAX_RETRANSMIT=2 Done
> coap post fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload Done
> coap put fdde:ad00:beef:0:2780:9423:166c:1aac test-resource con payload Done
Sets the URI path for the test resource.
> coap resource test-resource Done > coap resource test-resource Done
Sets the content sent by the test resource. If a CoAP client is observing the resource, a notification is sent to that client.
> coap set Testing123 Done
Starts the application coap service.
> coap start Done
Stops the application coap service.
> coap stop Done