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-posix 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 delete get post put resource start stop Done
List the CoAP CLI commands.
> 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
> 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
Starts the application coap service.
> coap start Done
Stops the application coap service.
> coap stop Done