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.
These BLE-Thread dynamic multiprotocol examples require you to run on the second board any complementary example that contains Thread CoAP Server functionality, for example:
The examples come with two variants presenting different BLE pairing options:
- Standard BLE Pairing (BLE Advertising after start)
- BLE Pairing using NFC
For more information about multiprotocol support, see Multiprotocol support with BLE/Bluetooth.
This example application is based on the UART/Serial Port Emulation over BLE example available in nRF5 SDK v16.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, the nRF52 SoC can 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
, using Nordic's BLE UART Service. When a UART command is sent from a mobile phone over BLE, the nRF52 device acts as 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 Switched MTD CoAP Client Example, transmitting and receiving data does not break connections from any of the used radio protocols (BLE or Thread).
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 that is advertising. After connecting, the example application behaves in the same way as the example with the NFC BLE pairing disabled, but 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 time-out, the library automatically triggers direct advertising.
The application allows to perform pairing in one of the following modes:
- Legacy Just Works pairing
- Legacy OOB pairing
- LE Secure Connections OOB pairing
Setup
You can find the source code and the makefile in the following folders (with or without BLE NFC Pairing):
<InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli
<InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli_nfc
LED assignments
The example uses LED assignments as described in Thread BSP LED and button reference for the following LEDs:
- LED1 – Used to indicate the network connection state.
- If you decide to use BLE Pairing using NFC, LED1 blinks when the NFC tag detects the NFC field.
The following LEDs reserved for user application purposes are assigned in this example:
- LED3 – Power consumption mode:
- Disabled - SED.
- Solid - MED.
- LED4
- On the server node before pairing, toggles in response to pressing the middle button on the smartphone or sending the "m" UART command.
- On the server node after pairing, toggles in response to pressing the left button on the smartphone or sending the "u" UART command.
MTD button assignments
The following buttons reserved for user application purposes are assigned in this example:
- Button 1: Send a unicast LIGHT_TOGGLE message to the
/light
resource on a paired device. If no device is paired with a specific client node, pressing the button has no effect.
- Button 2: Send a multicast LIGHT_ON or a LIGHT_OFF message (alternatively) to the
/light
resource. Sending a LIGHT_ON/LIGHT_OFF message instead of LIGHT_TOGGLE allows to synchronize the state of the LEDs on several server nodes.
- Button 3: Switch power consumption mode: from MED to SED and from SED to MED.
- Button 4: Send a multicast pairing request to the
/provisioning
resource.
UART command assignments
The following UART commands are used in this example:
- "u" - performs the same operation as Button 1 (send a unicast CoAP message over Thread)
- "m" - performs the same operation as Button 2 (send a multicast CoAP message over Thread)
- "p" - performs the same operation as Button 4 (send a pairing request as CoAP message over Thread)
Testing
- Note
- The following testing procedure uses the nRF52840 device.
- Prepare two nRF52840 Preview Development Kits and an Android smartphone (you can also use an iOS smartphone).
- On the smartphone, install nRF Toolbox for BLE.
- Run the following commands to flash the
simple_coap_server
example to one of the boards. $ cd <InstallFolder>/examples/thread/simple_coap_server/hex
$ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
- Switch on the board. LED1 starts blinking and then it turns solid.
- If you choose an example with BLE NFC pairing support, Install micro-ecc. This library is required by the Cryptography library .
- Build the example according to the instructions in Building examples.
- Flash SoftDevice and the example according to the instructions in Running examples on the second board.
- Sswitch the second board on.
- Depending on the chosen variant:
- BLE Pairing without using NFC: LED1 starts blinking (BLE advertising).
- BLE Pairing using NFC: Touch the NFC antenna with a smartphone, tablet, or the complementary central device example. LED1 blinks when the NFC tag detects the NFC field.
- Open nRF Toolbox and choose the UART application.
nRF Toolbox - UART application
- Tap EDIT. The Create button window appears.
- Create three active application buttons.
- Enter command "u" (EOL = LF)
- Enter command "m" (EOL = LF)
- Enter command "p" (EOL = LF)
nRF Toolbox - UART application - Configure button
- After all buttons are created, tap DONE.
- If the NFC BLE pairing feature is enabled, touch the NFC antenna with a smartphone and confirm pairing.
- Tap CONNECT and select the Thread_UART device.
nRF Toolbox - UART application after establishing the connection
- Observe that LED1 is solid, which indicates that BLE connection is established.
- You can control LED4 on every CoAP Server nodes by pressing the middle button ("m" - command) from your smartphone.
- Pair a client with a server.
- Press Button 4 on a server node to enable pairing.
- Press the right button in nRF Toolbox ("p" command) to pair the two nodes.
You can now control the LED4 on this server node by pressing the left button in nRF Toolbox ("u" - command). You can also control CoAP Servers directly from the nRF52 Development Kit by pressing Button 1, Button 2, or Button 4.