nRF5 SDK for Thread and Zigbee v4.1.0
BLE UART and Thread Switched MTD CoAP Client Example

Table of Contents

This information applies to the following SoCs: nRF52833 and nRF52840.
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 example application is based on the UART/Serial Port Emulation over BLE example available in nRF5 SDK. It has been modified to support switching between two connection modes, BLE and Thread:

The mode is switched from BLE to Thread in the following situations:

The mode is switched from Thread to BLE in these situations:

multi_interaction.png
Interaction of ble_thread_switched_mtd_coap_client and simple_coap_server examples

Setup

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

LED assignments

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

The LED assignments are different for the following LEDs:

Button assignments

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


Testing

The following testing procedure uses the nRF52840 device. It also refers to using an Android smartphone. You can use an iOS smartphone, but some screenshots can differ, pairing popups can appear, and for an iOS app you must ensure to convert all strings to ASCII HEX codes.

Precondition
This BLE-Thread switched MTD CoAP client multiprotocol example requires you to run Simple CoAP Server example. For more information about multiprotocol support, see Multiprotocol support with BLE/Bluetooth.
  1. Prepare two nRF52840 Preview Development Kits and an Android smartphone.
  2. On the smartphone, install nRF Connect for Mobile.
  3. Run the following commands to flash the simple_coap_server example to one of the boards and switch it on. LED1 starts blinking (attaching to a Thread network) and, after a few seconds, it turns solid (attached to a Thread network or Thread network created):
    $ cd <InstallFolder>/examples/thread/simple_coap_server/hex
    $ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
  4. Build the example according to the instructions in Building examples.
  5. Flash SoftDevice and the example according to the instructions in Running examples and switch the board on. LED1 starts blinking (BLE advertising).
  6. Open nRF Connect for Mobile and tap SCAN.
    nrfconnect_1.png
    nRF Connect for Mobile
    Note
    To auto-connect to the BLE device after it finishes operation on Thread network, select Use autoConnect in nRF Connect settings.
  7. Tap CONNECT next to the Nordic_UART device. LED1 on the ble_thread_switched_mtd_coap_client should be solid.
    nrfconnect_2.png
    nRF Connect for Mobile
  8. Tap Nordic UART Service. The service information appear.
    nrfconnect_3.png
    nRF Connect for Mobile
  9. Tap the arrow pointing up next to TX Characteristic. The Write value window appears.
    nrfconnect_4.png
    nRF Connect for Mobile
  10. Enter the string led and tap SEND. The following happens:
    • LED2 on the ble_thread_switched_mtd_coap_client board switches on for a few seconds and the client board starts the Thread attachment procedure.
    • When the Thread attachment procedure is finished, the client board sends a CoAP message to the simple_coap_server board through Thread.
    • When the message is received, the server board toggles LED4.
    • The client board disconnects the Thread network and LED2 switches off.
    • The client board starts BLE advertising, and LED1 starts blinking.
  11. When the ble_thread_switched_mtd_coap_client node starts advertising again, you can repeat the procedure starting from the step where you open nRF Connect for Mobile and tap SCAN.

Documentation feedback | Developer Zone | Subscribe | Updated