This example requires the following SoftDevice: S140
Important: Before you run this example, make sure to program the SoftDevice.
This dynamic multiprotocol example application is based on the Color Dimmer Switch, a Zigbee Home Automation device. This device can turn on and off several compatible light bulbs, dim them, and change their color. With this example, the device supports dynamic switching between two protocols, BLE and Zigbee, at the same time (concurrently). Furthermore, this example makes use of Finding & Binding feature, which allows the device to discover its peers on the network.
This example uses at least three devices:
- Zigbee light switch (multiprotocol)
- Zigbee coordinator
- Zigbee light bulb (one or more)
The light switch device operates through pressing buttons on the DK on the Zigbee network, and through the Nordic UART Service on the BLE network. Both networks are independent from each other. Three different Zigbee Endpoints are instantiated on the light switch (with numbers 1, 2, and 3), with the possibility to trigger Finding & Binding process on each of them.
To support both protocols at the same time, the Zigbee stack uses the 802.15.4 radio during the inactive time of the Bluetooth Low Energy radio (using Timeslot API). Depending on the Bluetooth Low Energy connection interval, the nRF52840 SoC can spend up to 99% of the radio time on the Zigbee protocol. This is the same mechanism as the one used in Dynamic multiprotocol examples in Thread.
For more information on multiprotocol operation, refer to the Multiprotocol support with BLE/Bluetooth support section.
- Note
- Transmitting and receiving data does not break connection from any of the used radio protocols, either BLE or Zigbee.
- Despite being based on the Color Dimmer Switch, the example does not necessarily need a Color Dimmable Bulb to operate. It can cooperate with any Zigbee device that uses On/Off cluster, Level Control cluster, Color Control cluster, or a combination of these clusters.
Setup
You can find the source code in the following folder: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_light_switch_nus
To show the basic behaviour of the device, you need two other examples that contain a Zigbee coordinator and a Zigbee light bulb. With these two examples, you can control the light bulb (On/Off and Level Control clusters). You can find these examples in Zigbee Light Control example.
- Note
- You can use the Arudino Joystick shield v1.A with this example. Plug it in the nRF52840 Development Kit, define the ARDUINO_JOYSTICK_SHIELD_V1A in code, and control the device using the built-in Joystick.
Assignments
You can control the devices either with the buttons on the development kits or the NUS UART commands in the nRF Toolbox application. The NUS UART commands offer more options than the DK buttons.
LED assignments
- All boards
- BSP_LED_2 – Turns on when the device has successfully joined the Zigbee network.
- Light bulb board
- BSP_LED_3 – After configuration:
- Turns on after pressing BSP_BUTTON_0 on the light switch board.
- When on, turns off after pressing BSP_BUTTON_1 on the light switch board.
- Light switch board
- BSP_LED_0: Shows BLE connection state:
- Blinking – BLE advertising.
- Continuously on – Connected over BLE.
- BSP_LED_1: Shows Finding & Binding process state:
- On – In progress.
- Off – Not in progress.
- BSP_LED_3:
- Blinking – Signalizes the Zigbee Endpoint that is currently selected (number of flashes equals the Endpoint number).
Button assignments
- Light bulb board
- BSP_BUTTON_0 – Starts the Identify process.
- Light switch board
- BSP_BUTTON_0
- Short press – After successful commissioning (BSP_LED_2 state), turns the Zigbee light bulb on.
- Note
- If the user decreases the brightness level to the minimum, the effect of turning on the light bulb might not be noticeable.
- Long press – Increases the brightness of the light bulb.
- BSP_BUTTON_1
- Short press – After successful commissioning (BSP_LED_2 state), turns off the Zigbee light bulb.
- Long press – Decreases the brightness of the light bulb.
- BSP_BUTTON_2
- Pressed when resetting the board: Enables the Sleepy End Device behaviour.
- Short press – Switches the Light Switch Endpoint to the next one. After switching the Endpoint, the device sends a ZCL Identify Trigger Effect request, which results in blinking of the bound bulbs (if any).
- BSP_BUTTON_3
- Short press – Starts or stops the Finding & Binding procedure on the currently selected Endpoint. The endpoint is bound with the Zigbee light bulb that is turned on, and in identifying process.
BLE UART command assignments
Command | Effect |
n | Turns on the Zigbee light bulb. |
f | Turns off the Zigbee light bulb. |
t | Toggles the Zigbee light bulb on or off. |
i | Increases the brightness level of the Zigbee light bulb. |
d | Decreases the brightness level of the Zigbee light bulb. |
sn | Selects the next Endpoint. |
sp | Selects the previous Endpoint. |
& | Starts or stops the Finding & Binding procedure on the currently selected Endpoint. |
h[vH]s[vS] | Moves the Color Bulb to the desired value of Hue and Saturation, [vH] and [vS] respectively, indicated by decimal values (from 0 to 255).
Example: h25s150 . |
[v] | [v] corresponds to a numeric value between 0 and 999. The command toggles the Zigbee light bulb after [v] seconds.
Example: 33 . |
Testing
For this example, prepare:
- at least three nRF52840 Development Kits;
- a smartphone (Android or iOS).
Configuring the boards
To evaluate the example, first configure the boards:
- Run the following commands to flash the Zigbee Coordinator example to one of the boards:
$ cd <InstallFolder>/examples/zigbee/light_control/light_coordinator/hex
$ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
- Run the following commands to flash the Zigbee dimmable light bulb example to all remaining boards:
$ cd <InstallFolder>/examples/zigbee/light_control/light_bulb/hex
$ nrfjprog -f nrf52 -r --program nrf52840_xxaa_pca10056.hex --chiperase
- Build this light switch example according to the instructions in Building examples.
- Flash SoftDevice and this light switch example according to the instructions in Running examples.
- Turn on all boards as described in Zigbee Light Control example (Testing section, steps 3 to 5). The BSP_LED_2 on every board turns on when the device starts.
- Press the BSP_BUTTON_0 on the light bulb board to start the identifying process on it.
- Press the BSP_BUTTON_3 on the light switch board to bind the bulb from the previous step to the selected endpoint.
- If you have more bulbs available, press BSP_BUTTON_2 on the light switch board to switch to the next endpoint. BSP_LED_3 on the light switch board changes the flashing pattern.
- Repeat steps 8-9 to bind the new bulb to the new endpoint.
- Note
- If you have a custom 3rd-party Color Dimmable Light Bulb, commission it to the network and put it into the Identify On mode - you could change its color as well.
The configuration of the boards is now complete.
Interacting with the boards
You can toggle BSP_LED_3 on the light bulb board bound to the currently selected endpoint in the network by pressing BSP_BUTTON_0 and BSP_BUTTON_1 on the light switch board.
After configuration, you can also start interacting with the boards using the nRF Toolbox application:
- On the smartphone, install nRF Toolbox for BLE.
- Open nRF Toolbox and select the UART application.
nRF Toolbox - UART application
- Tap EDIT.
- Configure the following nine application buttons (also listed in the BLE UART command assignments table):
- Configure command
n
- Configure command
f
- Configure command
t
- Configure command
i
- Configure command
d
- Configure command
sn
- Configure command
sp
- Configure command
&
- Configure command
h12s34
nRF Toolbox - UART application - Configure button
- When all buttons are configured, tap DONE.
- Tap CONNECT and select the ZIGBEE_UART light switch device.
nRF Toolbox - UART application after establishing the connection
- Observe that BSP_LED_0 on the multiprotocol light switch board is turned on and stops blinking, which indicates that a BLE connection has been established.
- Test the application buttons by pressing the buttons you assigned in the application in step 4:
n
and f
commands: Press the corresponding buttons to turn the BSP_LED_3 on the Zigbee light bulb node on and off, respectively.
t
command: Press the corresponding button two times to toggle the BSP_LED_3 on the Zigbee light bulb node on and off.
ssn
and sp
commands: Move through the endpoints with the corresponding buttons.
&
command: Press the corresponding button to initiate the Finding & Binding procedure.
- Hue and saturation command: Press the button configured to
h12s34
to move to the predefined Hue and Saturation value.
i
and d
commands: Press the corresponding buttons to adjust the brightness level.
Testing the [v] command
To test the delayed toggle command ([v]
command in the BLE UART command assignments table), add another button with the numeric command or create a separate configuration (screen).
nRF Toolbox - Add configuration
For example, you can add buttons to toggle the light bulb after 1 (1
command), 3 (3
command), and 9 (9
command) seconds.
nRF Toolbox - Delayed toggle commands