nRF5 SDK for Thread and Zigbee v1.0.0
Thread Cloud CoAP Client Example

The Thread Cloud CoAP Client example demonstrates the interaction between the development kit and a remote Cloud service. The nRF52840 node uses the built-in OpenThread CoAP protocol. This example uses the thethings.io cloud. However, the code can be easily modified to be used with a different CoAP cloud.

The client node sends the emulated temperature value each time BSP_BUTTON_0 or BSP_BUTTON_1 is pressed. Additionally, these buttons decrease and increase the value respectively. The example implements the CLI interface so that more advanced users can communicate with the nodes through the serial port and configure them manually.

Description

For proper operation, this example must be used along with Nordic's Thread Border Router to provide Internet connectivity to the Thread network. For more information, refer to Thread Border Router and Thread NCP Example.

After the Thread Border Router is set up, you must perform cloud and node configuration, which has been explained in the following sections.

Cloud setup

For a detailed description of the sign-up procedure and an introduction to the web interface of thethings.io, complete the steps described in thethings.io Getting Started. After the account is created, perform the following steps:

  1. Log in to the main control panel.
  2. Go to the Things Manager page.
  3. Create a new product. Choose JSON as the data type.
  4. Activate the Thing by clicking Activate More Things.
  5. After the Thing has been activated, copy the related Thing Token. Note that this Token must be copied into the nRF52840 Development Kit example source code.
    Note
    Before the Temperature Resource is visible in the Dashboard, you must push the first value using either the nRF52840 Development Kit or manually using, for example, a curl request:
    curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{"values":[{"key":"temp","value":"0"}]}' -X POST "https://api.thethings.io/v2/things/{THINGS_TOKEN} " –k
    Alternatively, you can keep track of the Thing resources in the detailed page of the Thing.
  6. Go to the Dashboard page.
  7. Optionally, remove all temporary created widgets by clicking Edit Dashboard.
  8. Click Add Widget (+).
  9. Fill in the name of the widget, for example Temperature, choose Thing Resource as a Data Source, and temp as a Resource.
  10. Use Gauge as Widget Type and check the Realtime check box.
  11. Optionally, you may also fill in the units, for example Celsius.
Note
Note that the control panel of thethings.io may change. In this case, refer to thethings.io Getting Started for information on how to activate a new Thing.

Node setup

As the first step, replace the Thing Token ({THING_TOKEN} string) with the appropriate one, obtained in the process of Cloud setup. The value can be found in the header of the main.c file represented as the CLOUD_URI_PATH define. After that, reprogram the example.

The nRF52840 node indicates the network state on BSP_LED_0. When the device is not connected to the network, the LED blinks at a 200 ms period. Once the device connects to a network, either as a Child or as a Leader, the LED stops blinking and remains turned on. On startup, nodes will automatically enter the network with default parameters. The first device that was turned on will become a Leader of the network, while the rest of the nodes will become Children and Routers.

The application layer of the example is built on top of the CoAP protocol. The client sends emulated temperature value when BSP_BUTTON_0 and BSP_BUTTON_1 are pressed.

The example application uses a minimum and maximum value of 15 and 30 Celsius that cannot be exceeded.

You can find the source code and the makefile in the following folder: <InstallFolder>\examples\thread\cloud_coap_client

Client LED assignments:

Client button assignments:

Troubleshooting

In case the temperature value is not sent, enter the command line interface (CLI) of the nRF52840 Development Kit and check if the address with fdff:cafe:cafe:cafe:: prefix is visible. If this prefix is not visible, the Border Router may be incorrectly set up.

Testing

To test the example, you need at least two development kits.

  1. Build the example according to the instructions in Building examples.
  2. Perform the cloud setup as described in Cloud setup and enter the dashboard page.
  3. Run Nordic's Thread Border Router along with the Thread NCP Example.
  4. Program the nRF52840 Development Kit with this Thread Cloud CoAP Client example.
  5. Turn on the node and wait until BSP_LED_0 stops blinking. The node should connect to the existing network.
  6. You can control the temperature value by pressing BSP_BUTTON_0 and the BSP_BUTTON_1 on the client node.
  7. Observe the Cloud Dashboard to see that the value has changed.
  8. Optionally, you can connect to any of the nodes through a serial port and run CLI commands. The application uses the following UART settings:
    • Baud rate: 115.200
    • 8 data bits
    • 1 stop bit
    • No parity
    • HW flow control: None
    For complete CLI documentation, refer to OpenThread CLI Reference.

Documentation feedback | Developer Zone | Subscribe | Updated