5.5 BLE ZigBee Provisioning Low Power Application Demo: Zigbee Multi-Sensor and Zigbee Commissioning through BLE
This section helps users to create a low power enabled multiprotocol (BLE+ZIGBEE) example project using MCC. The step by step procedure helps users 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 Board | 1 |
Micro USB cable | 1 |
Android/iOS Mobile | 1 |
Software Requirement
SDK Setup
Smartphone App
-
Microchip Bluetooth Data (MBD) iOS/Android app available in stores
Programming the Precompiled Hex File or Application Example
The demo needs two devices as described below:
- Combined Interface: One of the WBZ451 Curiosity boards is programmed with Combined Interface which can act as Zigbee Gateway/Coordinator. Program the CI pre-compiled hex image by following the steps mentioned in the “Programming the precompiled hex file or Application Example” section of the Zigbee Centralized Network Formation by Combined Interface application, on one curiosity board.
- ble_zigbee_multisensor: Another WBZ451 Curiosity board is programmed with ble_zigbee_multisensor application which can act as Zigbee end device. Follow the below step for programming ble_zigbee_multisensor application on another curiosity board.
Programming the .hex
File using MPLAB X IPE
- Import and program the
precompiled
.hex
file is located in"<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\multiprotocol\ble_zigbee_multisensor\Hex"
folder - For more details on the steps, go
to Programming a DeviceNote: Users must choose the correct device and tool information
Programming the Application using MPLAB X IDE
- Follow steps mentioned in the Running a Precompiled Example section.
- Open and program the application
example "
ble_zigbee_multisensor.x
" located in "<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\multiprotocol\ble_zigbee_multisensor\firmware"
using MPLAB X IDEFor more details on finding the Harmony content path, refer to Installing the MCC Plugin
Demo Description
This application demonstrates the Zigbee Multi-Sensor end device joining to Zigbee Coordinator (Combined Interface, The third party 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.
Demo Steps
- The steps explained in Joining Multi-Sensor with the WBZ451 Combined Interface (CI) Coordinator can be followed to connect with the WBZ451 based Combined Interface which acts as Zigbee Coordinator.
Joining Multi-Sensor with the WBZ451 Combined Interface (CI) Coordinator
Hardware and Software Setup
- Supply power to the WBZ451 Curiosity board consisting of Combined Interface application by connecting a USB cable. Power Supply (PS) Green LED will turn ON when connected to the PC.
- Open TeraTerm and configure as
mentioned below:Terminal Settings
- Baud Rate/Speed – 115200 (as configured in SERCOM configuration)
- Parity – None
- Data Bits – 8
- Stop Bits – 1
- Flow Control – None
For more details on how to set the “Serial Port” and “Speed”, refer to COM Port Setup
Additionally, local echo and sending line ends with line feeds shall be enabled in the PC serial terminal application.
Network Formation (Coordinator - (Combined Interface))
Follow the steps explained in Network Formation (Coordinator - (Combined Interface)) to open up the network in CI.
Commissioning (End Device - Multi-Sensor)
- Supply power to the WBZ451 Curiosity board which is programmed with BLE Zigbee Multi-Sensor image by connecting a USB cable. Once commissioning is initiated via MDB, the BLE Zigbee Multi-Sensor will search for Zigbee coordinator device and will join to network and initiate Finding & Binding.
- Launch MBD Microchip Bluetooth
Data app from mobile. Open BLE Provisioning feature and scan for the
devices.
- Look for the device labeled as “Combo_Multisensor” in the scan results.
- Establish a connection with the device and refer to the subsequent screenshots provided for guidance on the commissioning process.
Note:- The Combo Multisensor is configured with default primary channel mask (11,15,20,25) as per Zigbee specification. The channel configuration from mobile app is needed only when the Gateway channel is not in any of the default channels.
- If commissioning procedure, does not find the nearby network (for example, Echo Plus), try to find the channel of the network, and configure the same channel while commissioning
- When the Combo Light is joined to an existing network/formed its own network, the device state can be seen as “Commissioned” as illustarted in the above figure.
- When the commissioning is started from the MBD app, the following will be printed to the Combined Interface terminal:
-
Success log on Combo Light when commissioned with Combined Interface
- Once BLE Zigbee Multi-Sensor finishes Finding & Binding procedure, it will start attribute reporting. The Combined Interface terminal log prints the received attribute information as illustrated below.
- Status messages during
commissioning: below status messages can be observed during the commissioning
procedure based on the conditions.
-
Device Joined to an existing network
-
Device formed its own network.
Figure 5-112. Device Forming New Network -
Fail Status: commissioning has failed (did not join/create own network)
Figure 5-113. Commissioning Failed
-
Developing the Application from Scratch using MCC
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
For developing Combined Interface from scratch, refer to the “Creating Application Device Types from Scratch using MCC” section of the Zigbee Centralized Network Formation by Combined Interface
This tutorial explains developing ble_zigbee_multisensor application from scratch
Pull-in H3 Components
- Create a new MCC Harmony Project. For more details, refer to Creating a New MCC Harmony Project.
- Import component configuration –
This step helps users setup the basic components and configuration required to
develop this application. The imported file is of format
.mc3
and is located in the path"<Harmony Content Path>\wireless_apps_pic32cxbz2_wbz45\apps\multiprotocol\ble_zigbee_multisensor\firmware\ble_zigbee_multisensor.X".
For more details on importing the component configuration , refer to Importing Existing App Example Configuration
Note: Import and export functionality of Harmony component configuration will help users to start from a known working setup of MCC configuration - Verify the project graph and configuration options shown in the below steps.
- Another method is manually adding
and configuring the components in project graph
- From “Device Resources”
field, select + BLE ZIGBEE PROVISIONING component (Device
Resources>Wireless>System Services), to add it in
project graph.
Figure 5-114. BLE ZIGBEE PROVISIONING - Accept all dependencies
by selecting Yes. Click on the Zigbee Device dependency on
the “BLE ZIGBEE PROVISIONING”, and select MultiSensor. The
project graph will appear as illustrated in the figure below
Figure 5-115. Project Graph - From “Device Resources”
field, select + TCC2 component, to add it in project graph.
Figure 5-116. TCC2 Figure 5-117. Project Graph -
Select the Multi Sensor Zigbee device component by clicking on the component in the project graph. Now the “Configuration Options” tab lists the Configurations for the selected Zigbee device. Ensure that the Manual Configuration is enabled and Network Formation Commissioning is enabled and AUTOMATIC COMMISSIONING ON STARTUP is disabled as illustrated in the following figure.
Figure 5-118. Multi Sensor -
Select the BLE Stack component by clicking on the component. In the “Configuration Options” tab, Expand Generic Access Profile (GAP)>Advertising>Advertising Data and Scan Response Data.
-
In “Advertising Data” menu, ensure that Local Name is disabled and enabled in Scan Response Data>Local Name. In “Advertising Data” menu, ensure that Service Data is enabled, Service UUID is set as
0xFEDA
and Service Data is set as0xFF03
as illustrated in the following figure.Figure 5-119. BLE Stack Configuration Note:0xDAFE
is a 16-bit Service UUID which is purchased by Microchip from Bluetooth SIG.- In
order to list the device while scanning in Microchip
Bluetooth Data (MBD) mobile application, the device
must advertise with Service UUID as
0xDAFE
and Service Data as 0xFF03.
- From “Device Resources”
field, select + BLE ZIGBEE PROVISIONING component (Device
Resources>Wireless>System Services), to add it in
project graph.
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
Figure 5-120. Low Power Configuration 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.
- 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 runningFigure 5-121. FreeRTOS -
-
RTC clock source must be set manually, there are four 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 MCC, Click
Plugins>Clock Configuration from drop down menu
Figure 5-122. Clock Configurations - In Clock Diagram,
-
Enable Secondary Oscillator (SOSC) by setting
SOSCEN
to ON -
Select SOSC as clock source for
VBKP_32KCSEL
and setLPCLK_MOD
toDIV_1_024
as illustrated in the following figureFigure 5-123. Clock Configuration Figure 5-124. Clock Configuration
-
- All Unused pins in the
application needs to be set in input mode and the pulldown must be enabled for
these pins. This can be configured inside ports available in system component
configuration options.
Figure 5-125. System Configurations - The Pin PB5 functionality must be
changed to GPIO to disable the JTAG functionality for reduced power consumption.
Figure 5-126. Pin Configuration Figure 5-127. Pin Configuration Tab - The PMU mode can be set to
BUCK_PWM mode to attain less power consumption and the settings are available as
part of Device Support as illustrated in the following figure.
Figure 5-128. Device Support
Generating a Code
Now all the required components have been added to the project and necessary configuration modification is made. The next step is to generate the application code.
For more details on code generation, refer to the MPLAB Code Configurator(MCC) Code Generation section.
Files and Routines Automatically Generated by the MCC
BLE, Zigbee Stack Initialization and Application Callback Registration:
The RF System, BLE System, ZIGBEE, PERIPHERAL initialization routine executed during
program initialization can be found in SYS_Initialize()
of
initialization.c
file.
Zigbee_Init()
from
initialization.c
is called.initialization.c
The BLE stack initialization routine executed during application initialization can
be found in APP_BleStackInit()
in app.c
. This call
initializes and configures different BLE layers like GAP, GATT, SMP, L2CAP and BLE
middleware layers and registers the application layer callbacks. The event callbacks
from BLE stack, BLE middleware and profile/service layer are registered.
APP_BleConfigBasic()
APP_BleConfigBasic()
app.c
app.c
file is
autogenerated and has a state machine for application callback handling from BLE,
Zigbee stacksapp.c
BLE Zigbee Provisioning Manual Code Configuration
-
zigbeeAppDeviceSelect.h
- Default Generated: “#define CS_UID 0 //Unique Identifier (UID) determining the device extended address”
- Change to a unique
value: “#define CS_UID 0x123bee //Unique Identifier (UID)
determining the device extended address”
Figure 5-134. zigbeeAppDeviceSelect.h
Note: By default, the coordinator also has the same value. In a network the UID value must be unique
Open app.c
file and include the header fileapp_prov.h
as illustrated in the following figure.#include "app_prov/app_prov.h"
Figure 5-135. app.c
- In
app.c
, add the following code afterAPP_BleStackInit()
inAPP_Tasks
function.APP_Prov_TRPS_Init();
Figure 5-136. app.c
- Open
app_ble_handler.c
file located inapp_ble
project folder. InAPP_BleGapEvtHandler()
function, add the following code as illustrated in the following figure.extern void APP_BleGapConnEvtHandler(BLE_GAP_Event_T *p_event); APP_BleGapConnEvtHandler(p_event);
Figure 5-137. app_ble_handler.c
- Open
app_trsps_handler.c
file. InAPP_TrspsEvtHandler()
function, add the below code as illustrated in the following figure.extern void APP_TRPS_EventHandler(BLE_TRSPS_Event_T *p_event); APP_TRPS_EventHandler(p_event);
Figure 5-138. app_trsps_handler.c
- Open
app_zigbee_handler.c
file, located inapp_zigbee
project folder. InZigbee_Event_Handler()
function, add the below code as illustrated in the following figure.extern void BZ_Prov_Zigbee_Event_Handler(APP_Zigbee_Event_t event); BZ_Prov_Zigbee_Event_Handler(event);
Figure 5-139. app_zigbee_handler.c
-
Build Project, upon building project user action is required as mentioned User Action.
- Open
app_user_edits.c
file. Comment out or remove the #error line. Update thefreertos_hooks.c
as mentioned inapp_user_edits.c
file
- Open
- Compile and Run the project in the WBZ451 Curiosity board.
Protocol Exchange
-
The communication protocol exchange between BLE Provisioner mobile app and the WBZ451 Module (BLE peripheral) is explained in the Zigbee Commissioning through BLE - Protocol Exchange section.