The :ref:`Thread <ug_thread>` CoAP Server sample demonstrates controlling light resources within an OpenThread network. This sample exposes resources in the network. To access them, you need another sample that is compatible with the OpenThread network. The recommended sample referenced on this page is :ref:`coap_client_sample`.
The sample supports the following development kits:
.. table-from-sample-yaml::
You can use one or more of these development kits as the Thread CoAP Server. You also need one or more compatible development kits programmed with the :ref:`coap_client_sample` sample.
This sample demonstrates how to expose resources that can be accessed by other devices in the same Thread network. You can use this sample application as a starting point to implement a :ref:`CoAP <zephyr:coap_sock_interface>` application.
The following CoAP resources are exposed on the network by this sample:
/light
- used to control LED 4/provisioning
- used to perform provisioning
This sample uses the native `OpenThread CoAP API`_ for communication. For new application development, use :ref:`Zephyr's CoAP API<zephyr:coap_sock_interface>`. For example usage of the Zephyr CoAP API, see the :ref:`coap_client_sample` sample.
- Button 4:
- Pressing results in entering the pairing mode for a limited period of time.
- LED 1:
- Lit when the OpenThread connection is established.
- LED 3:
- Blinks when the pairing mode is enabled.
- LED 4:
- Turned on and off by messages sent from the client nodes.
The sample provides predefined configuration files for typical use cases, and to activate sample extensions. You can find the configuration files in the root directory of the sample.
Specify the corresponding file names in the :makevar:`OVERLAY_CONFIG` option when building. See :ref:`cmake_options` for instructions on how to add this option. For more information about using configuration overlay files, see :ref:`zephyr:important-build-vars` in the Zephyr documentation.
:file:`overlay-logging.conf` is a configuration file that enables logging using RTT. For additional options, refer to :ref:`RTT logging <ug_logging_backends_rtt>`.
|enable_thread_before_testing|
After building the sample and programming it to your development kit, complete the following steps to test it:
Program at least one development kit with the :ref:`coap_client_sample` sample and reset it.
Turn on the Simple CoAP Client node. This node becomes the Thread network Leader.
Turn on all the other nodes, including the Simple CoAP Server nodes. They enter the network as Children, and gradually become Routers.
Note
It can take up to 15 seconds for Thread to establish the network.
Press Button 2 on the client node to control LED 4 on all server nodes.
To pair a client with a server, complete the following steps:
- Press Button 4 on a server node to enable pairing.
- Press Button 3 on a client node to pair it with the server node in the pairing mode.
Press Button 1 on the client node to control the LED 4 on the paired server node.
You can connect to any of the Simple CoAP Server or Simple CoAP Client nodes with a terminal emulator |ANSI|. For more details, see :ref:`putty`.
Once the serial connection is ready, you can run OpenThread CLI commands. For complete CLI documentation, refer to `OpenThread CLI Reference`_.
Note
In Zephyr shell, every OpenThread command needs to be preceded with the ot keyword.
For example, ot channel 20
.
This sample uses the following |NCS| libraries:
In addition, it uses the following Zephyr libraries:
- :ref:`zephyr:kernel_api`:
include/kernel.h
OpenThread CoAP API is used in this sample:
In addition, it uses the following secure firmware component: