nRF51 IoT SDK
|
The CoAP over DTLS Client example demonstrates how DTLS can be integrated to Nordic's CoAP implementation for the client role.
The supplied CoAP client example has the same behavior as the CoAP client examples in terms of access of resources on the server. However this client example requests access of CoAP resources on the default CoAPS port 5684 instead of the default CoAP port 5683.
This example application, although referred to as CoAP client, is technically an example of concurrent CoAP Client and Server implementation. However, the DTLS state can be maintained only for one role at any given point and accessing both roles simultaneously may result in undesired, unexpected behavior.
As a CoAP Client, this application sends LED state control requests to the Light Server Example application, as demonstrated in Figure 1. For the first message initiated by this client example, DTLS handshake is initiated and the message is buffered until handshake is complete.
Additionally, as a CoAP Server, temperature is exposed as a resource that can be GET and PUT from the CoAP client on the PC and shown in Figure 2.
These examples are designed to complement the CoAP server example applications. The server is identified by its IPv6 address, which needs to be configured in main.c
.
The client examples also implement an endpoint that hosts the following resources:
host |-- .well-known | `-- core `-- sensors `-- thermometer
The thermometer resource simply stores an integer value in the range of -100 to +100, to demonstrate that the device can be set up to work as a CoAP client and server concurrently.
Configuration parameters for all used modules are defined and described in the sdk_config.h file, which is located in the main application folder.
This section summarizes the usage of nRF51 resources and common modules in the examples apart from the IoT 6lowpan and IPv6 stack library.
Module | Inclusion/Usage | Description |
---|---|---|
Timer | 2 | Two timers are used one for IoT timer and the other for the button module. |
Buttons | 2 | Buttons are used for initiating CoAP requests. See Button assignments section for details. |
LEDs | 4 | LEDs are used to indicate the application states. See LED assignments section for details. |
Adv Data Encoder | Yes | The device name used is 'DTLS-COAPClient', IPSP Service UUID is included in the UUID list. |
RNG Driver | Yes | Random number generator is used for security procedures in tinyDTLS library. |
Scheduler | No | Scheduler is used for processing stack events. |
UART Trace | Included not enabled | Tracing is included but not enabled by default. |
The example named iot_dtls_coap_client uses Nordic's IPv6 stack to set up the CoAP server with DTLS is implemented using the tinyDTLS library. You can find the source code and project files of this example in the following folder:
<InstallFolder>/Nordic/nrf51/examples/iot/dtls/coap_client
LED assignments:
LED 1 | LED 2 | |
---|---|---|
Blinking | Off | Device advertising as BLE peripheral. |
On | Blinking | BLE link established, IPv6 interface down. |
Off | On | BLE link established, IPv6 interface up. |
On | On | Assertion failure in the application. |
Button assignments:
This example is designed to work with the CoAP over DTLS Server example. However, if only one nRF51 DK is available, the Californium CoAP Framework can be used as a secure CoAP Server on a PC.
See Connecting devices to the router for a list of relevant Linux commands.
main.c
to set the correct IPv6 server address.sysctl -w net.ipv6.conf.all.forwarding=1
.