2017-08-28 16:25:11 +08:00
|
|
|
.. _coaps-server-sample:
|
2017-04-05 03:00:08 +08:00
|
|
|
|
2017-01-20 06:28:49 +08:00
|
|
|
CoAP over DTLS sample server
|
|
|
|
############################
|
|
|
|
|
|
|
|
Overview
|
2017-01-31 06:54:22 +08:00
|
|
|
********
|
2017-01-20 06:28:49 +08:00
|
|
|
This sample code shows a CoAP over DTLS server using mbedTLS on top of Zephyr.
|
|
|
|
|
|
|
|
Building and Running
|
2017-01-31 06:54:22 +08:00
|
|
|
********************
|
2017-01-20 06:28:49 +08:00
|
|
|
|
2017-06-07 18:18:03 +08:00
|
|
|
Follow the steps for testing :ref:`networking_with_qemu`.
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
In the application directory type:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-07-31 21:13:19 +08:00
|
|
|
$ make run
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
In other terminal window, obtain the libcoap code from:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-07-31 21:13:19 +08:00
|
|
|
$ git clone --recursive -b dtls https://github.com/obgm/libcoap.git
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
and put it in a well known directory, in your Linux machine, this will be your
|
|
|
|
client. In order to compile libcoap you may need to install the following
|
|
|
|
libraries, for Ubuntu
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-07-31 21:13:19 +08:00
|
|
|
$ sudo apt-get install libtool asciidoc
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
Move to that directory and compile the libcoap on your host machine
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-07-31 21:13:19 +08:00
|
|
|
$ ./autogen.sh
|
|
|
|
$ ./configure --disable-shared
|
|
|
|
$ make all
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
Now you can run the client like
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-07-31 21:13:19 +08:00
|
|
|
$ cd examples
|
|
|
|
$ ./coap-client -m get coaps://[2001:db8::1]/test -u Client_identity -k passwd
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
You will get the following output:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
v:1 t:CON c:GET i:7154 {} [ ]
|
|
|
|
decrypt_verify(): found 24 bytes cleartext
|
|
|
|
decrypt_verify(): found 123 bytes cleartext
|
|
|
|
Type: 0
|
|
|
|
Code: 1
|
|
|
|
MID: 29012
|
|
|
|
|
|
|
|
From the app directory type the screen should display
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
*******
|
|
|
|
type: 0 code 1 id 29012
|
|
|
|
*******
|
|
|
|
mbedtls_ssl_read returned -0x7780
|
|
|
|
|
|
|
|
If the server does not receive the messages, restart the app and try to connect
|
|
|
|
the client again.
|
|
|
|
|
|
|
|
References
|
2017-01-31 06:54:22 +08:00
|
|
|
**********
|
2017-01-20 06:28:49 +08:00
|
|
|
|
|
|
|
* https://tls.mbed.org/
|
|
|
|
* https://libcoap.net/
|