nRF5 SDK for Thread and Zigbee v1.0.0
Choose documentation:
BLE Thingy and Zigbee Color Light Bulb Example
This example requires the following SoftDevice: S140

Important: Before you run this example, make sure to program the SoftDevice.

This Zigbee dynamic multiprotocol example demonstrates how to control multiple BLE peripherals using a multiprotocol BLE Central/ZED device.

Description

The device is combining two application roles:

  • BLE role - as a central it connects to a specified number of Thingy52 devices and enables the control for the application.
  • Zigbee role - as a sleepy end device it represents a device with two color light bulb endpoints.

In the application, both roles are connected to create a relationship between two Zigbee endpoints and two Thingy52 devices. After power on, the device initializes the BLE stack and Zigbee stack, and starts scanning. Simultaneously, the application tries to connect to the Zigbee network and Thingy52 devices. For every connected Thingy device, the application discovers characteristics, reads the current LED characteristic value and the battery level, and changes Thingy's LED from breathing blue color to constant red.

For every Zigbee endpoint in the relationship, incoming commands such as ON/OFF control, level control, or color control are processed. The commands control LED on the Thingy that is related with the endpoint. See the following chart for an example of a working application.

zigbee_dynamic_light_sed_thingy_master.jpg
Example of working application for one of endpoints

LED assignments:

  • BSP_LED_0 - Is ON when application is scanning on BLE.
  • BSP_LED_1 - Is ON when Thingy connects, OFF when scanning.
  • BSP_LED_2 - Is ON when the device is connected to the Zigbee network.

This application does not use buttons.

Note
Because of the discovery sequence, make sure that only Thingy52 is connected to the application.

Setup

You can find the source code and the makefiles in the following folder:

  • <InstallFolder>\examples\multiprotocol\experimental\ble_zigbee_dynamic_color_light_bulb_thingy

Testing

Precondition
To test this example, you need three nRF52840 Development Kits and one or two Thingy52 IOT Sensor Kits.

The light switch example (see Zigbee Light Control example) allows for testing only one of two endpoints. If you want to use a light switch to control the Thingy52 LED, make sure that there are no other light bulb devices in the network. There is no guarantee that using more than one light switch will let you control both endpoints, because every light switch can connect to the same endpoint.

  1. Build the example according to the instructions in Building examples.
  2. In the light switch example, in MATCH_DESC_REQ_ROLE change ZB_NWK_BROADCAST_RX_ON_WHEN_IDLE to ZB_NWK_BROADCAST_ALL_DEVICES in main.c to enable the light switch to work also with sleepy end devices:
    • Before change:
      #define IEEE_CHANNEL_MASK (1l << ZIGBEE_CHANNEL) /**< Scan only one, predefined channel to find the coordinator. */
      #define LIGHT_SWITCH_ENDPOINT 1 /**< Source endpoint used to control light bulb. */
      #define MATCH_DESC_REQ_START_DELAY (2 * ZB_TIME_ONE_SECOND) /**< Delay between the light switch startup and light bulb finding procedure. */
      #define MATCH_DESC_REQ_TIMEOUT (5 * ZB_TIME_ONE_SECOND) /**< Timeout for finding procedure. */
      #define MATCH_DESC_REQ_ROLE ZB_NWK_BROADCAST_RX_ON_WHEN_IDLE /**< Find only non-sleepy device. */
    • After change:
      #define IEEE_CHANNEL_MASK (1l << ZIGBEE_CHANNEL) /**< Scan only one, predefined channel to find the coordinator. */
      #define LIGHT_SWITCH_ENDPOINT 1 /**< Source endpoint used to control light bulb. */
      #define MATCH_DESC_REQ_START_DELAY (2 * ZB_TIME_ONE_SECOND) /**< Delay between the light switch startup and light bulb finding procedure. */
      #define MATCH_DESC_REQ_TIMEOUT (5 * ZB_TIME_ONE_SECOND) /**< Timeout for finding procedure. */
      #define MATCH_DESC_REQ_ROLE ZB_NWK_BROADCAST_ALL_DEVICES /**< Find sleepy and non-sleepy device. */
  3. Build the light switch example from <InstallFolder>\examples\zigbee\experimental\light_control\light_switch.
  4. Build the coordinator example from <InstallFolder>\examples\zigbee\experimental\light_control\light_coordinator.
  5. Flash the SoftDevice and the examples according to the instructions in Running examples.
  6. Start the coordinator and wait until its BSP_LED_2 turns on.
  7. Start the application and the light switch.

When the Development Kit on which the application is running successfully joins the network, its BSP_LED_2 turns ON and the Thingy52 LED changes color from breathing blue to constant red to indicate the established connection. As soon as both BSP_LED_2 and BSP_LED_3 on the light switch turn ON, the light switch is ready to control one of the Thingy52 LEDs, and you can:

  • Turn the LED ON and OFF by pressing BSP_BUTTON_0 and BSP_BUTTON_1 on the light switch.
  • Make the LED brighter or dimmer by pressing and holding BSP_BUTTON_0 and BSP_BUTTON_1 on the light switch.