The Switched BLE-Thread Template example demonstrates the usage of the switched multiprotocol method. This example is a merge of a simplified version of BLE Peripheral Template and Thread CLI Example applications.
The nRF52840 device can operate in the following modes:
- BLE Peripheral mode – sends connectable advertisements.
- Thread FTD mode – provides OpenThread’s built-in command line interface (CLI), and automatically attaches to the Thread network.
Description
By default, the application starts in the BLE Peripheral mode. To select a mode, press the buttons on the nRF52840 Development Kit.
When you press BSP_BUTTON_2, application disables the BLE stack (SoftDevice) and enables the Thread stack, which is indicated by BSP_LED_1. The device starts Thread attachment procedure.
When you press BSP_BUTTON_3, the application disables the Thread stack and reinitializes the BLE stack (SoftDevice), which is indicated by BSP_LED_1. The device starts to advertise.
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_2: Switch protocol from BLE to Thread
- BSP_BUTTON_3: Switch protocol from Thread to BLE
Setup
You can find the source code and the makefile in the following folder: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_swi_template
Testing
- Prepare at least one nRF52840 Preview Development Kit and an Android smartphone.
- On the smartphone, install nRF Connect for Mobile.
- Compile and program the SoftDevice and the application. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Connect to the device from nRF Connect (the device is advertising as Nordic_Template). Observe that the BSP_INDICATE_CONNECTED state is indicated.
- Disconnect the device in nRF Connect and observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Switch from BLE mode to Thread mode by pushing BSP_BUTTON_2.
- Observe that BSP_LED_1 is lit, and so is BSP_LED_0 after the node is attached to the Thread network.
- Connect to the board through UART. The application uses the following UART settings:
-
Baud rate: 115200
-
8 data bits
-
1 stop bit
-
No parity
-
HW flow control: None
Refer to OpenThread CLI reference for complete reference of the OpenThread Command Line Interface.
- Run the
state
command to check the state of the device in the Thread network: - Note
- If there are any other Thread devices using the same channel and PANID, the observed state can be
router
or child
.
- Switch from Thread mode to BLE mode again by pushing BSP_BUTTON_3.