Skip to content

Example : DTLS CoAP Server

Michael edited this page Mar 28, 2017 · 5 revisions

6LBR CoAP library has introduced a generic transport layer in “er-coap”, allowing to use other transport protocols than UDP. In this example we will demonstrate how to use DTLS and communicate from a computer to an embedded node using CoAP over DTLS.

Compilation of the node firmware

Configure TinyDTLS

TinyDTLS must be manually configured before compilation. To do so navigate to ‘apps/tinydtls’ and run to create the necessary configuration files. (Note: The script requires the autoconf package to be installed on your system!)

cd apps/tinydtls

If the directory is empty you first need to checkout the submodules:
git submodule update —init —recursive

Build firmware

The argument WITH_DTLS_COAP=1 must be used in conjunction with WITH_TINYDTLS=1 for TinyDTLS to build.
This allows different DTLS implementations to be developed and dynamically included in the future. Replace TARGET with your target device.

cd examples/6lbr-demo

Upload firmware

The last step is to upload the firmware to the target device, i.e. if you use a MSP430:

Set the node in bootloader mode 
msp430-bsl5-uart -p /dev/ttyUSB0 --parity-none --erase=0x8000-0x3FFFF 6lbr-demo.wismote
Reset the node

Getting the Java client

To access the CoAP server the client needs to be enabled to use DTLS. Not many CoAP client implementations are DTLS enabled. In this example the Californium CoAP client programmed in Java will be used.

Old Californium client

You could for example use Californium-0.13.7 cf-client example to test the CoAP server. Download Californium, extract it and go in run directory. There create to set up the identity hint to use :


If you have modified the pre-shared key or using a later version of Californium/Scandium, you have to update it in the sharedKeys map present in Add or update the following line with your pre-shared key :

sharedKeys.put("Client_identity", new byte[] { 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x50, 0x53, 0x4b });

New Californium client

Check out the current version from git and build the .jar file. To do this make sure your host has maven installed.

git clone
mvn clean install

This will place all .jar-files in the run directory.

You can also just build the example client from the project and copy it to the run directory by doing:

cd cf-client
mvn clean install
cp target/cf-client-<version>.jar ../run

Client commands

Note: Check the port (5683/5684) the CoAP server is listening on first by checking the UART command line. It it should be added the command line.

Note: Depending on your configuration you need to add the -psk argument to the command line. This will force you to enter the client identity (“Client_identity”) and pre-shared key (“secretPSK”).


To connect to the node server and display the /.well-known/core resource, use:

cd Californium/run
java -jar cf-client-<version>.jar DISCOVER coaps://[<node address>]:<port>/


To connect to the node server and display a single resource, use:

cd Californium/run
java -jar cf-client-<version>.jar GET coaps://[<node address>]:<port>/dev/runtime


To connect to the node server and change a single resource, use:

cd Californium/run
java -jar cf-client-<version>.jar PUT coaps://[<node address>]:<port>/dev/runtime <VALUE>
Clone this wiki locally
You can’t perform that action at this time.