This BLE-Thread switched multiprotocol example requires you to run the following example:
For more information about multiprotocol support, see Multiprotocol support with BLE/Bluetooth.
BLE-Thread switched MTD CoAP client example
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:
- BLE mode – In this mode, the example works just like
ble_app_uart
, using Nordic's BLE UART Service.
- Thread mode – In this mode, the node that is running the example application starts attaching to a Thread mesh network. When the attachment procedure succeeds, the node sends a multicast CoAP message to toggle the LED on the
simple_coap_server
example board. After transmission of the CoAP message, the device switches back to the BLE mode.
The mode is switched from BLE to Thread in the following situations:
- Button 3 is pressed.
- String
led
is received through the Bluetooth connection.
The mode is switched from Thread to BLE in these situations:
- CoAP message containing the LED toggle request is sent.
- Thread timeout expires (10 seconds).
LED assignments:
- BSP_LED_0: Network state:
- Blinking - BLE advertising.
- Solid - Connected over BLE or over Thread.
- BSP_LED_1: Active network stack:
- Disabled - BLE.
- Solid - Thread.
Button assignments:
- BSP_BUTTON_0: Wake up from BLE Sleep mode.
- BSP_BUTTON_2: Switch protocol from BLE to Thread.
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
Testing
- Note
- The following procedure refers to using an Android smartphone. You can also 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.
- Prepare two nRF52840 Preview Development Kits and an Android smartphone.
- On the smartphone, install nRF Connect for Mobile.
- Run the following commands to flash the
simple_coap_server
example to one of the boards and switch it on. LED 1 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
- Build the example according to the instructions in Building examples.
- Flash SoftDevice and the example according to the instructions in Running examples and switch the board on. LED 1 starts blinking (BLE advertising).
- Open nRF Connect for Mobile and tap SCAN.
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.
- Tap CONNECT next to the Nordic_UART device. LED 1 on the
ble_thread_switched_mtd_coap_client
should be solid.
nRF Connect for Mobile
- Tap Nordic UART Service. The service information appear.
nRF Connect for Mobile
- Tap the arrow pointing up next to TX Characteristic. The Write value window appears.
nRF Connect for Mobile
- Enter the string
led
and tap SEND. The following happens:
- LED 2 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 LED 4.
- The client board disconnects the Thread network and LED 2 switches off.
- The client board starts BLE advertising, and LED 1 starts blinking.
- 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.