The OpenThread CoAPS APIs may be invoked via the OpenThread CLI.
Use the COAPS=1
build switch to enable CoAPS API support.
> ./bootstrap
> make -f examples/Makefile-posix COAPS=1
Form a network with at least two devices.
CoAPS uses DTLS to establish a secure, end-to-end connection.
This example supports two ciphersuites:
-
TLS_PSK_WITH_AES_128_CCM_8
> coaps psk <your-psk> <your-psk-id> Done
-
TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
> coaps x509 Done
The X.509 certificate stored in core/cli/x509_cert_key.hpp
.
On node 1, setup CoAPS server with resource test-resource
.
> coaps start
Done
> coaps resource test-resource
Done
> coaps start
Done
> coaps connect <peer-ip6-address>
Done
coaps connected
> coaps get test-resource
Done
coaps response from fdde:ad00:beef:0:9903:14b:27e0:5744 with payload: 68656c6c6f576f726c6400
> coaps put test-resource con payload
Done
coaps response from fdde:ad00:beef:0:9903:14b:27e0:5744
On node 1, you should see output similar to below:
coaps request from fdde:ad00:beef:0:9e68:576f:714c:f395 GET
coaps response sent
coaps request from fdde:ad00:beef:0:9e68:576f:714c:f395 PUT with payload: 7061796c6f6164
coaps response sent
> openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
> openssl req -x509 -new -key ec_private.pem -out x509_cert.pem -days 30
> coaps help
help
connect
delete
disconnect
get
post
psk
put
resource
start
stop
x509
Done
List the CoAPS CLI commands.
Establish DTLS session.
- address: IPv6 address of the peer.
> coaps connect fdde:ad00:beef:0:9903:14b:27e0:5744
Done
coaps connected
- uri-path: URI path of the resource.
- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
- payload: CoAPS request payload.
> coaps delete test-resource con payload
Done
> coaps disconnect
coaps disconnected
Done
- uri-path: URI path of the resource.
- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
> coaps get test-resource
Done
- uri-path: URI path of the resource.
- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
- payload: CoAPS request payload.
> coaps post test-resource con payload
Done
Set DTLS ciphersuite to TLS_PSK_WITH_AES_128_CCM_8
.
- psk: pre-shared key
- pskid: pre-shared key identifier
> coaps psk 123 pskid
Done
- uri-path: URI path of the resource.
- type: "con" for Confirmable or "non-con" for Non-confirmable (default).
- payload: CoAPS request payload.
> coaps put test-resource con payload
Done
Sets the URI path for the test resource.
> coaps resource test-resource
Done
> coaps resource
test-resource
Done
Starts the application coaps service.
- checkPeerCert: Peer Certificate Check can be disabled by typing false.
> coaps start
Done
Stops the application coaps service.
> coaps stop
Done
Set DTLS ciphersuite to TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
.
The X.509 certificate stored in src/cli/x509_cert_key.hpp
.
> coaps x509
Done