nRF5 SDK for Thread and Zigbee v4.1.0
BLE HRS and Thread CoAP Server with FreeRTOS Example

Table of Contents

This information applies to the nRF52840 SoC only.
This example requires the following SoftDevice: S140

Important: Before you run this example, make sure to program the SoftDevice.

Warning
There is an issue in the nRF5 SDK for Thread and Zigbee v4.1.0 that causes higher-than-usual sleep power consumption for all multiprotocol examples when using nRF52840. See workaround on DevZone.

This BLE-Thread dynamic multiprotocol example requires you to run on the second board any complementary example that contains Thread CoAP Server functionality, for example:

For more information about multiprotocol support, see Multiprotocol support with BLE/Bluetooth.

The Thread FreeRTOS CoAP Server example uses the thread-safe variants of the OpenThread libraries that do not support hardware acceleration (see Mandatory libraries). This example is not supported on Keil.

This example application is based on the Heart Rate Application with FreeRTOS example available in nRF5 SDK v13.0.0. It has been extended to support dynamic switching between two connection modes, BLE and Thread, at the same time (concurrently). Thread operates on the 802.15.4 radio during Bluetooth low energy radio's inactive time (using Timeslot API). Depending on the Bluetooth low energy connection interval, nRF52840 SoC can spend up to 99% of the radio time on Thread protocol.

This example also supports the Thread CoAP Server role, as described in the Simple CoAP Server example.

The application works similarly to ble_app_hrs_freertos, using the BLE HRS Profile. When not using BLE, nRF52840 SoC acts as a Thread CoAP Server controlling LED3 and LED4.


Setup

You can find the source code and the makefile in the following folder: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_hrs_coap_srv_freertos

LED assignments

The example uses LED assignments as described in Thread BSP LED and button reference for the following LEDs:

The following LEDs reserved for user application purposes are assigned in this example:

Button assignments

The following buttons are assigned in this example on the server:

The following buttons are assigned in this example on the client:


Testing

  1. Prepare two nRF52840 Preview Development Kits and an Android smartphone (you can also use an iOS smartphone).
  2. On the smartphone, install nRF Toolbox for BLE.
  3. Run the following commands to flash the simple_coap_client example on one of the boards:
    $ cd <InstallFolder>/examples/thread/simple_coap_client/hex
    $ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
  4. Switch the board. This board becomes the CoAP Client node. LED1 starts blinking and then turns solid to indicate that the board is connected to a Thread network.
  5. Build the example according to the instructions in Building examples.
  6. Flash SoftDevice and the example according to the instructions in Running examples on the second board.
  7. Switch the second board. This board becomes the server node. LED1 starts blinking.
  8. Open nRF Toolbox and tap HRM.
  9. Tap CONNECT and select Thread_HRS. You can now see data sent by the HRS example.
  10. Observe that LED1 on the server node is solid, which indicates that BLE connection has been established.
  11. You can control blinking of LED3 and LED4 on the node by pressing Button 2 on the CoAP Client node.
  12. Pair a client with a server:
    1. Press Button 4 on the server node to enable pairing.
    2. Press Button 4 on any client node to pair the two nodes.

You can now control the blinking of LED3 and LED4 on this server node by pressing Button 1 on the client node.


Documentation feedback | Developer Zone | Subscribe | Updated