5.5 BLE ZigBee Provisioning Low Power Application Demo: Zigbee Multi-Sensor and Zigbee Commissioning through BLE

This tutorial helps users to create a low power enabled multiprotocol (BLE+ZIGBEE) example project using Mplab code configurator. The step by step procedure will help the user to generate a Zigbee Multi-Sensor application and commission the Multi-Sensor to a Zigbee network through BLE from scratch.

Hardware Requirement

Tool Qty
WBZ451 Curiosity Board1
Micro USB cable1
Android/iOS Mobile1

SDK Setup

Getting Started with Software Development

Smartphone App

Microchip Bluetooth Data (MBD) iOS/Android app available in stores

Demo Description

This application demonstrate the Zigbee Multi-Sensor end device joining to Zigbee Coordinator (Combined Interface, The thirdparty gateway's like Amazon Echo plus can also be used instead of CI.) by receiving the commissioning parameters from user using a mobile phone through BLE Link. The mobile application uses Microchip Proprietary Transparent Service to send and receive data PIC32CX-BZ2/WBZ451 device.

The BLE provisioner in the MBD App (available in Google Play Store and Apple Store) is utilized to demo the provisioning functionality.

Developing the Application from Scratch using Mplab Code Configurator

The following steps will help to understand the PIC32CXBZ2 device ZIGBEE and BLE stack programming structure. Ensure that wireless_system_pic32cxbz2_wbz45 repo is available locally as documented in Getting Started with Software Development

Pull-in H3 Components

  • Create a new MPLAB Code Configurator Project. Follow the instructions in 2.5 Creating a New MCC Harmony Project.

  • Open MPLABx Code Configurator. The Wireless System Service components will be displayed in available components. Select BLE ZIGBEE PROVISIONING from Device Resouces --> Wireless -->System Services as shown in the below figure.

  • Accept all dependencies by selecting "Yes". Click on the Zigbee Device dependency on the BLE ZIGBEE PROVISIONING, select MultiSensor. The project graph will appear as shown in the figure below.

  • Select the Multi Sensor Zigbee device component by click on the component in the project graph. Now the Configuration Options tab will list the Configurations for the selected Zigbee device. Ensure that the Manual Configuration is selected and Network Formation Commissioning Enable and AUTOMATIC COMMISSIONING ON STARTUP is deselected as shown in below figure.

  • Select the BLE Stack component by clicking on the component. In the Configuration Options tab, Expand Generic Access Profile (GAP) --> Advertising and then expand Advertising Data and Scan Response Data.

  • In Advertising Data menu, ensure that Local Name is deselected and selected in Scan Response Data --> Local Name. In Advertising Data menu, ensure that Service Data is selected, Service UUID is selected as 0xFEDA and Service Data is set as 0xFF03 as shown in below figure.

Note:
  1. 0xFEDA is a 16-bit Service UUID which is purchased by Microchip from Bluetooth SIG.
  2. In order to list the device while scanning in Microchip Bluetooth Data (MBD) mobile application, the device must advertise with Service UUID as 0xFEDA and Service Data as 0xFF03.

Low Power Configuration

  • Enable Sleep Mode in BLE stack H3 component configuration, after enabling this dependent component like RTC (Timer source during sleep) will be requested to be enabled

For Zigbee applications the System Sleep mode is only enabled when using the following device types - Multisensor, Intruder Alarm System and Color Scene controller as per the Zigbee End Device Spec. 
There is no separate configuration that a user has to select to enable the System Sleep like for BLE Sleep
  • Upon enabling sleep mode, FreeRTOS related settings will be set automatically.
    • Tick Mode will be set to Tickless_Idle

    • Expected idle time before sleep will be set to 5 (ms)

    • Tick Hook will be enabled (For user to add any custom code needed to be executed within each tick interrupt)

    • RTC peripheral library will be added and configured

    Note: RTC counter must not be reset (RTC_Timer32CounterSet()) arbitrarily when the system is running
  • RTC clock source must be set manually, there are 4 options to choose from:

    • FRC (±1% offset)

    • LPRC ( with larger offset, < ±5%)

    • POSC <- Candidate of the clock source (better clock accuracy)

    • SOSC <- Candidate of the clock source (better clock accuracy)

    Users can select POSC or SOSC as the RTC clock source. Choosing FRC and LPRC as clock sources for RTC will impact BLE connection stability. In this example SOSC is configured as RTC clock source.

  • In Mplab Code Configurator, Click Plugins select "Clock Configuration" from drop down menu
  • In Clock Diagram,
    • Enable Secondary Oscillator (SOSC) by setting SOSCEN to ON

    • Select SOSC as clock source for VBKP_32KCSEL and set LPCLK_MOD to DIV_1_024 as hown in below below.

  • All Unused pins in the application needs to be set in input mode and the pulldown should be enabled for these pins. This can be configured inside ports available in system component confguration options.
  • The Pin PB5 functionality should be changed to GPIO to disable the JTAG functionality for reduced power consumption.
  • The PMU mode can be set to BUCK_PWM mode to attain less power consumption and the settings is available as part of Device Support as shown in the figure Below.

BLE Zigbee Provisioning Manual Code Configuration

  • Open app.c file and include the header file app_prov.h as illustrated in the following figure.
#include "app_prov/app_prov.h"
  • In app.c, Add the following code after APP_BleStackInit() in APP_Tasks function.
APP_Prov_TRPS_Init();
  • Open app_ble_handler.c file located in app_ble project folder. In APP_BleGapEvtHandler() function, add the following code as shown in figure.
extern void APP_BleGapConnEvtHandler(BLE_GAP_Event_T *p_event);
APP_BleGapConnEvtHandler(p_event);
  • Open app_trsps_handler.c file. In APP_TrspsEvtHandler() function, add the below code as shown in figure.
extern void APP_TRPS_EventHandler(BLE_TRSPS_Event_T *p_event);
APP_TRPS_EventHandler(p_event);
  • Open app_zigbee_handler.c file located in app_zigbee project folder. In Zigbee_Event_Handler() function, add the below code as shown in figure.
extern void BZ_Prov_Zigbee_Event_Handler(APP_Zigbee_Event_t event);
BZ_Prov_Zigbee_Event_Handler(event);
  • Open app_user_edits.c file. Comment out or remove the #error line. Update the freertos_hooks.c as mentioned in app_user_edits.c file
  • Compile and Run the project in WBZ451

Demo Steps: Commissioning

To Commission the Zigbee Multi-Sensor device, follow the step mentioned here

Protocol Exchange

  1. The communication protocol exchange between BLE Provisioner mobile app and WBZ451 Module (BLE peripheral) is explained in 5.4 Zigbee Commissioning through BLE - Protocol Exchange.