nRF5 SDK for Thread and Zigbee v1.0.0
BLE UART and Thread MTD CoAP Client Examples

This BLE-Thread dynamic multiprotocol examples require you to run any complementary example on the second board, i.e. an example containing Thread CoAP Server functionality, for example:

The examples come with two variants presenting different BLE pairing options:

This example application is based on the ble_app_uart example available in nRF5 SDK v15.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 may spend up to 99% of the radio time on Thread protocol.

This example also supports the Thread MTD CoAP Client role, as described in the MTD CoAP Client example.

The application works similarly to ble_app_uart, utilizing Nordic's BLE UART Service. When a UART command is sent from a mobile phone over BLE, nRF52840 acts as Non-sleepy MTD CoAP Client and sends unicast or multicast CoAP messages to toggle the LED on the simple_coap_server example board.

Note
Unlike in the BLE UART and Thread MTD CoAP Client Example, transmitting and receiving data does not break connections from any of the used radio protocols (BLE or Thread).

LED assignments:

MTD client button assignments:

UART command assignments:

NFC

One variant of the application shows the usage of the NFC BLE pairing library. The application initializes and starts the NFCT peripheral, which is used for pairing. The application does not start advertising immediately, but only when the NFC tag is read by an NFC polling device, for example a smartphone or a tablet with NFC support. The message that the tag sends to the NFC device contains data required to initiate pairing. To start the NFC data transfer, the NFC device must touch the NFC antenna that is connected to the nRF52 Development Kit.

After reading the tag, the device can pair with the nRF52 device which is advertising. After connecting, the example application behaves in the same way as the example with NFC BLE pairing disabled with one difference. The security level for the Nordic UART Service has been raised to the highest possible level - level 4, so that it is possible for the central device to turn on the UART only after a proper pairing procedure. When the connection is lost due to timeout, the library automatically triggers direct advertising.

The application allows to perform pairing in one of three different modes:

Setup

You can find the source code and the makefile in the following folders (with or without BLE NFC Pairing):

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_server example to one of the boards and switch it on. LED 1 will start blinking (attaching to a Thread network) and, after a few seconds, it will turn 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.hex --chiperase
  4. If you choose example with BLE NFC pairing support, please Install micro-ecc. This library is required by the Cryptography library .
  5. Build the example according to the instructions in Building examples.
  6. Flash SoftDevice and the example according to the instructions in Running examples and switch the board on.
  7. Depending on the chosen variant:
    • BLE Pairing without using NFC: LED 1 will start blinking (BLE advertising).
    • BLE Pairing using NFC: Touch the NFC antenna with a smartphone, tablet, or the complementary central device example. BSP_LED_0 blinks when the NFC tag detects the NFC field.
  8. Open nRF Toolbox and choose the UART application.
    nrftoolbox_dynamic_uart_1.png
    nRF Toolbox - UART application
  9. Tap EDIT and create three application buttons.
    • Enter command "u" (EOL = LF)
    • Enter command "m" (EOL = LF)
    • Enter command "p" (EOL = LF)
      nrftoolbox_dynamic_uart_2.png
      nRF Toolbox - UART application - Configure button
  10. After all buttons are created, tap DONE.
  11. If the NFC BLE pairing feature is enabled, touch the NFC antenna with a smartphone and confirm pairing.
  12. Tap CONNECT and select the Thread_UART device.
    nrftoolbox_dynamic_uart_3.png
    nRF Toolbox - UART application after establishing the connection
  13. Observe that BSP_LED_0 is solid, which indicates that BLE connection has been established.
  14. You can control BSP_LED_3 on every CoAP Server nodes by pressing the middle button ("m" - command) from your smartphone.
  15. Pair a client with a server. Press BSP_BUTTON_3 on a server node to enable pairing. Then, press the right button in nRF Toolbox ("p" command) to pair the two nodes.
  16. You can now control the BSP_LED_3 on this server node by pressing the left button in nRF Toolbox ("u" - command).
  17. You can also control CoAP Servers directly from the nRF52840 Development Kit by pressing BSP_BUTTON_0, BSP_BUTTON_1, or BSP_BUTTON_3.

Documentation feedback | Developer Zone | Subscribe | Updated