nRF5 SDK for Thread and Zigbee v4.1.0
BLE UART and Zigbee Door Lock Example

Table of Contents

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.

This dynamic multiprotocol example application is based on the Door Lock, a Zigbee Home Automation device that steers the door lock. The device functionalities have been extended to support dynamic switching between two protocols, BLE and Zigbee, at the same time (concurrently). The door lock can be closed or opened through either the corresponding Zigbee ZCL commands or the BLE UART (with the device acting as a BLE peripheral).

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 (through Timeslot API). Depending on the Bluetooth low energy connection interval, the nRF52 SoC can spend up to 99% of the radio time on the Zigbee protocol. This is the same mechanism as the one used in the Thread's Dynamic multiprotocol examples.

For more information on multiprotocol operation, refer to the Multiprotocol support with BLE/Bluetooth support section.

Note
Transmitting and receiving data does not break connections from any of the radio protocols used (neither BLE nor Zigbee).

Moreover, the state of the door lock of the device in this example persists between power outages. The state of the lock is stored in the Flash Data Storage subsystem. You can also control the servo motor with the PWM (Pulse Width Modulation). The servo motor is fed from the pin LOCK_MECHANISM_PIN.


Setup

You can find the source code in the following folder: <InstallFolder>\examples\multiprotocol\ble_zigbee\ble_zigbee_dynamic_door_lock_nus

LED assignments

The example uses LED assignments as described in Thread BSP LED and button reference for the following LEDs:

The following LEDs reserved for user application purposes are assigned in this example:

UART command assignments

The following BLE UART commands are configured in this example:


Testing

Precondition
To test this example, prepare two nRF52 Development Kits and a smartphone (Android or iOS). You also need an other board with CLI agent that will serve as a Zigbee Coordinator and also a Zigbee Door Lock Controller. See Zigbee CLI Agent example.

Before you start testing locking and unlocking the door, complete the following steps:

  1. On the smartphone, install nRF Toolbox for BLE.
  2. Prepare the Zigbee coordinator with the Zigbee CLI agent. Refer to Zigbee CLI Reference for complete reference of the Zigbee Command Line Interface.
  3. Compile and program the SoftDevice and the application. The BSP_INDICATE_ADVERTISING state is indicated.
  4. Connect to the device from nRF Connect (the device is advertising as 'Zigbee_Door_Lock'). The BSP_INDICATE_CONNECTED state is indicated.
  5. Disconnect the device in nRF Connect. The BSP_INDICATE_ADVERTISING state is indicated.
  6. Run the role command to set the state of the CLI device in the Zigbee network and then start it:
    > bdb role zc
    Coordinator set
    Done
    > bdb start
    Started coordinator
    Done
  7. Observe that the LED3 indicates that the device has commissioned.
  8. Observe that the LED4 indicates that the door is open (state of the door lock is unlocked).
  9. Get the address of the Door Lock using Match Descriptor Request:
    > zdo match_desc ffff ffff 0104 1 0101 0
    src_addr=47D8 ep=8
    Done
    Note
    The short address of the device returned by the Match Descriptor Request might differ in your case.
  10. Get the IEEE address of the Door Lock:
    > zdo ieee_addr 0x47D8
    0b010e1585785ce7
    Done
    Note
    The long address of the device returned by the Extended Address Request might differ in your case.

Locking the door

To lock the door, use the following ZCL command:

> zcl cmd 0b010e1585785ce7 8 0101 -p 0104 00
Done

Observe the change of state on the LED or PWM, or both.

Unlocking the door

To unlock the door, use the following ZCL command:

> zcl cmd 0b010e1585785ce7 8 0101 -p 0104 01
Done

Observe the change of state on the LED or PWM, or both.

Locking and unlocking the door with nRF Toolbox

  1. Open nRF Toolbox and choose the UART application.
    nrftoolbox_dynamic_zigbee_uart_1.png
    nRF Toolbox - UART application
  2. Tap EDIT.
  3. Configure two application buttons:
    • Enter command "sesame" for opening the door.
    • Enter command "hodor" for closing the door.
      nrftoolbox_dynamic_zigbee_uart_6.png
      nRF Toolbox - UART application - Configure button
  4. After all buttons are configured, tap DONE.
  5. Tap CONNECT.
  6. Select the Zigbee_Door_Lock device.
    nrftoolbox_dynamic_zigbee_uart_7.png
    nRF Toolbox - UART application after establishing the connection
  7. Observe that LED1 on the multiprotocol light switch board is turned on, which indicates that a BLE connection has been established.

You can now control the door lock by issuing Open command ("sesame") and Close command ("hodor") from your smartphone. Every time you issue a command, you can observe the change of the LED4 or PWM levels, or both.


Documentation feedback | Developer Zone | Subscribe | Updated