36
Introduction Bluetooth ® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh networking capability for internet of things (IoT) solutions. It integrates STM35WBx5 products with embedded Bluetooth Low Energy technology communication in a powerful, range-extending mesh network with two-way wireless communication. The solution contains the core functionality for secure communication and provides all the flexibility needed to build applications. It uses STM32WBx5 devices with mesh stack APIs and related event callbacks. The software development kit (SDK) provides the mesh stack in library form and a sample application in source code to demonstrate how to use the library. BLE mesh can be used in several applications requiring infrequent data transfer in a mesh network over Bluetooth ® Low Energy technology, to create distributed control systems such as: Smart lighting Home and building automation Industrial automation The examples in this application note are to be used together with the P-NUCLEO-WB55 pack for which a demonstration example is available. The demonstration example used to change the application interface, uses the library for the required hardware and software functionalities. The demo application is available for the P-NUCLEO-WB55 pack. The sample application implements smart light control scenarios, which can be modified to suit specific requirements. How to build a Bluetooth ® Low Energy mesh application for STM32WBx5 microcontrollers AN5292 Application note AN5292 - Rev 1 - March 2019 For further information contact your local STMicroelectronics sales office. www.st.com

How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

  • Upload
    others

  • View
    88

  • Download
    3

Embed Size (px)

Citation preview

Page 1: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

IntroductionBluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh networkingcapability for internet of things (IoT) solutions. It integrates STM35WBx5 products with embedded Bluetooth Low Energytechnology communication in a powerful, range-extending mesh network with two-way wireless communication.

The solution contains the core functionality for secure communication and provides all the flexibility needed to build applications.It uses STM32WBx5 devices with mesh stack APIs and related event callbacks. The software development kit (SDK) providesthe mesh stack in library form and a sample application in source code to demonstrate how to use the library.

BLE mesh can be used in several applications requiring infrequent data transfer in a mesh network over Bluetooth® Low Energytechnology, to create distributed control systems such as:• Smart lighting• Home and building automation• Industrial automation

The examples in this application note are to be used together with the P-NUCLEO-WB55 pack for which a demonstrationexample is available. The demonstration example used to change the application interface, uses the library for the requiredhardware and software functionalities. The demo application is available for the P-NUCLEO-WB55 pack.

The sample application implements smart light control scenarios, which can be modified to suit specific requirements.

How to build a Bluetooth® Low Energy mesh application for STM32WBx5 microcontrollers

AN5292

Application note

AN5292 - Rev 1 - March 2019For further information contact your local STMicroelectronics sales office.

www.st.com

Page 2: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

1 General information

This document applies to STM35WBx5 Arm®-based microcontrollers.

Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.

AN5292General information

AN5292 - Rev 1 page 2/36

Page 3: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

2 Getting started

The sample application in this document implements a smart lighting control scenario. To modify the application,the following steps are to be applied in sequence:1. Step 1. Connect the board to the PC2. Step 2. Compile the firmware in IDE3. Step 3. Flash the firmware to the board4. Step 4. Provision the board in the STM32WB-mesh application5. Step 5. Toggle LED on board using the application.

2.1 Board interfacesThe following table details the P-NUCLEO-WB55 pack for the power management application and user interface,for example LEDs and buttons.

Table 1. Hardware details

Devices Hardware kit Powered by Programmed by LEDs Buttons

STM32WBx5 P-NUCLEO-WB55pack

Micro USB cable or CR2032 battery USB port 3 user LEDs + 2

power indicationReset button + 3user buttons

2.2 P-NUCLEO-WB55 pack board setupConnect the main P-NUCLEO-WB55 pack board to the host PC with a USB cable. This cable is used for twopurposes:• To provide power to the P-NUCLEO-WB55 pack board;• Provide a serial data link between the PC and the P-NUCLEO-WB55 pack board.

The P-NUCLEO-WB55 pack board integrates the ST-LINK/V2-1 debugger/ programmer. The relevant version ofthe STSW-LINK009 ST-LINK/V2-1 USB driver for the version of Microsoft® Windows® are availabel onwww.st.com .The general board layout is shown in Figure 1. STM35WBx5 board connection with PC.

Note: Ensure that STM35WBx5 is updated with BLE stack version 1.0.0 or higher. The STM32 ST-LINK Utility GUI canbe used to manage the update.

AN5292Getting started

AN5292 - Rev 1 page 3/36

Page 4: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Figure 1. STM35WBx5 board connection with PC

STM32WBx5 microcontroller

User buttons

User LEDs

Reset button Power supply through USB or external source

This photo is not contractuel

2.3 System requirementsThe minimum system requirements to set up and run the BLE mesh smart lighting application are:• PC with Intel or AMD processor running one of the following Microsoft operating systems:

– Windows®XP®

– Windows®VISTA®

– Windows 7®

– Windows 10®

• At least 128 Mbytes of RAM• 2 x USB ports• 40 Mbytes of hard disk space• Development toolchains and compilers:

– Keil® µVision® v5.23– IAR Embedded Workbench v8.20.2 .

2.4 Installing BLE meshTo install the BLE mesh, follow the steps :1. Extract the contents of the package in a temporary directory2. Launch the installer and follow the on-screen instructions3. Install in suitable folder on the disk-drive.

AN5292System requirements

AN5292 - Rev 1 page 4/36

Page 5: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

3 Firmware structure

Figure 2. Firmware architecture

LED light demo

Util

ities

C

MSI

S

Applications

Drivers

Middleware

LED light demo Custom application

Cryptographic library

BLE-Core stack

BLE-mesh library

Hardware abstraction layer

Board Support Package

Hardware

P-NUCLEO-WB55 pack main board

The firmware package is built with the following structure and is illustrated in the diagram above:• A Documentation folder with a set of compiled HTML files which are generated from the source code

together with the detailed description of all the software components and APIs;• A Driver folder with the hardware abstraction layer (HAL) and board specific drivers to support the hardware

platforms and components toghether with the CMSIS vendor-independent hardware abstraction layer for theCortex®-M processor series.

• A Middleware folder with the mesh and BLE communication libraries:– Horizontal interaction between layer components is directly handled by calling the feature APIs, while

vertical interaction with the low level drivers is managed through specific callbacks and static macrosimplemented in the library system call interface;

– BLE mesh library v1.09.000 is built according the Bluetooth SIG mesh Profile v1.0 and mesh modelv1.0 specifications as described in the Figure 3. BLE mesh library architecture.

• A Project folder containing the workspaces for IAR Embedded Workbench integrated developmentenvironments for the P-NUCLEO-WB55 pack board;

• The EWARM folder containing the workspace for IAR Embedded.The source files in the folder binds thefirmware layers to implement the functions that demonstrate mesh over BLE functionality.

AN5292Firmware structure

AN5292 - Rev 1 page 5/36

Page 6: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Figure 3. BLE mesh library architecture

Model definition: basic functionality of a node state / massages / behavior for a mesh network

Defines use of the upper transport layer for higher layer applications. Opcode multiplexing models

Take access payload from Access Layer and transmit message to peer upper transport layer with encryption and authenticationTake Upper Transport PDU and transmit messages to peer lower transport layer with segmenetation and reassemblyDefine network PDU format for transport of lower PDU by bearer layer.Message format network encryption and authentication

Sending messages between nodes:With advertising data of a BLE advertising PDU using Mesh message AD type (advertising bearer).With proxy protocol over GATT connection (GATT bearer)

Models

Access layer

Transport upper layer

Lower transport layer

Network layer

Network layer Network layer

Note: GATT stands for Generic ATTribute

The folder structure is outlined in Figure 4. Folders, sub-folders and contents of the package.

AN5292Firmware structure

AN5292 - Rev 1 page 6/36

Page 7: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Figure 4. Folders, sub-folders and contents of the package

AN5292Firmware structure

AN5292 - Rev 1 page 7/36

Page 8: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

3.1 Root folderThe figure below shows the root folder structure of the firmware package.

Figure 5. Root folder structure

The driver folder contains the low level drivers for the devices and P-NUCLEO-WB55 pack board

including the BSP, HAL, peripheral drivers and the CMSIS

This folder contains the project for the BLE mesh demo

Middleware folder that contains the BLE mesh library cryptographiclibrary and

communication drivers

3.2 Driver folderThe driver folder contains all low level drivers including peripheral drivers and HAL drivers corresponding to thehardware. The strucutre is detailed in the figure below.

Figure 6. Driver folder

BSP (board support package) for the P-NUCLEO-WB55 pack board.

CMSIS (cortex microcontroller software interface standards) is the hardware abstraction layer for ARM® Cortex-M processor.

This folder contains the driver for the peripherals for STM32WBx5 microcontroller.

AN5292Root folder

AN5292 - Rev 1 page 8/36

Page 9: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

3.3 Project folderThe project folder folder contains the projects for IAR. As illustrated in the figure below.

Figure 7. Internal project folder

STM32WBx5 setup source and include file

IAR project workspace

Application source and include files

Mailbox source file for communication between M0 and M4

AN5292Project folder

AN5292 - Rev 1 page 9/36

Page 10: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

3.4 Middleware folderThe middleware folder, illustrated below, contains the middleware project including pre-compiled mesh library fortheSTM35WBx5.

Figure 8. Middleware folder

BLE middleware

ST crytographic library

Mesh model files

AN5292Middleware folder

AN5292 - Rev 1 page 10/36

Page 11: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

4 Using the BLE mesh demo

The embedded IAR workbench is used to debug and burn the firmware into the P-NUCLEO-WB55 pack boardFlash memory.

4.1 Using the STM32WBx5 binaries1. The pre-compiled binaries are available in Project\<Platform>\Application\<Demo>\ EWARM\<Demo Name>

\Exe folder. For example, for STM32WB55RG, the path is Projects\NUCLEO-WB55.Nucleo\Applications\BLE\ble_mesh_lighting_demo\EWARM\Lighting\Exe\BLE_Lighting_Demo.bin;

2. These can be programmed in the device using different utilities such as ST LINK or any IntegratedDevelopment Environment;

3. Use “ST-LINK Utility” tool to program the P-NUCLEO-WB55 pack boards connected via mini-USB cable;4. Or, simply drag and drop the .bin file in the drive created by ST-LINK on the P-NUCLEO-WB55 pack board.

The binary is programmed in the STM35WBx5 device on the P-NUCLEO-WB55 pack board.The process is illustrated in the figure below.

Figure 9. Overview of how to program the binary in the STM32WB55RG MCU

1 Go to Projects\NUCLEO-WB55.Nucleo\Applications\BLE\BLE_MeshLightingDemo\EWARM\Production\Exe

32

4

Select BLE_Lighting_Demo.bin

P-NUCLEO-WB55 pack main board

Connect the board

Flash the board using STM32 ST-Link Utility

AN5292Using the BLE mesh demo

AN5292 - Rev 1 page 11/36

Page 12: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

4.2 Using IAR project1. Choose file / open / workspace. Select the ble_mesh_lighting_demo.eww file from the appropriate

location. For example, for the STM35WBx5 BLE mesh demo, the location is as follows:stm32wb_M4_Firmware\Firmware\Projects\NUCLEO-WB55.Nucleo\Applications\BLE\ble_mesh_lighting_demo\EWARM.

2. A project opens in the workspace. This project contains all the project files and folders (such as driver files,application files, middleware, output files...).

3. Build the program with Project / Make Option.4. Press the download and debug buttons to debug the code and flash it to the board.5. Press the Go button to run the program.

AN5292Using IAR project

AN5292 - Rev 1 page 12/36

Page 13: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

5 Firmware initialization and configuration

This section describes the available API functions for application development based on mesh network overBluetooth Low Energy (BLE) devices.The mesh over BLE library manages the following features:• Creates the mesh network between nodes• Handles the unicast, broadcast addressing• Manages the relay feature: all the packets whose destination address are for other nodes are re-transmitted• Communication with devices for advanced features, such as provisioning and proxy service• Handles the platform specific communication.

The user application handles the following:• Initialization of the mesh stack• User callbacks required for the application• Application handling.

The following chapter describes the requirements for the firmware initialization and configuration.

5.1 Setting the transmit power of a nodeThe node transmit power is defined by initializing a callback to the mesh library. It runs as follows:

{ Appli_BleStackInitCb, Appli_BleSetTxPowerCb, Appli_BleGattConnectionCompleteCb, Appli_BleGattDisconnectionCompleteCb, Appli_BleUnprovisionedIdentifyCb, Appli_BleSetUUIDCb, Appli_BleSetNumberOfElementsCb};

The Appli_BleSetTxPowerCb() calls the aci function to set the poweraci_hal_set_tx_power_level(uint8_t En_High_Power, uint8_t PA_Level);By default, +4 dbm is configured in the nodes for STM35WBx5, this can however be changed by the user.

5.2 UART interface on the firmwareThe boards can be connected to a PC via a USB connection. Any software terminal (using HyperTerminal,Hercules or Putty for exmaple) can be used to open the serial communication port on the PC to check themessages sent by the board.The board UART controller is connected to the PC via a virtual communication (VCOM ) port. The settings toopen the communication port are:• Baud: 115200• data size: 8• parity: none• stop bits: 1• no hardware control.

From the firmware main.c file, certain messages can be printed to the VCOM using the following code:

#if !defined(DISABLE_TRACES) /* Prints the MAC Address of the board */ printf("BLE-Mesh Lighting Demo v%s\n\r", BLE_MESH_APPLICATION_VERSION); printf("BLE-Mesh Library v%s\n\r", BLEMesh_GetLibraryVersion()); printf("BD_MAC Address = [%02x]:[%02x]:[%02x]:[%02x]:[%02x]:[%02x] \n\r", bdaddr[5],bdaddr[4],bdaddr[3],bdaddr[2],bdaddr[1],bdaddr[0] );#endif

AN5292Firmware initialization and configuration

AN5292 - Rev 1 page 13/36

Page 14: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

After the board is connected and the terminal window is opened, press the reset button. If the firmware startssuccessfully, a window opens displaying messages from the virtual com window as shown in the figure below.

Figure 10. VCOM window

5.3 MAC address managementEach node in the mesh network requise a unic MAC address. The following table describes the available optionsto configure the MAC addresses for a node

Table 2. MAC address management

Number MAC addressManagement Comments

1 Using external MAC address

User can program the nodes with desired unique MAC address. This is stored atspecific location in the flash. It is the user’s responsibility to make sure that theprogrammed MAC address in the device is compliant with the Bluetoothcommunication requirements.

2 Using the unique deviceserial number

It is possible to configure the MAC address of the device using the unique serialnumber available in each device.

This is the default setting.

3 Using static random MACaddress

It is possible to configure the MAC address of devices using the static random MACaddress

5.4 Button usageThe following table describes what operations are available using the onboard buttons.

Table 3. Button usage and LEDs management

Features Buttons LEDs

Mesh Lib error - LED2 flashes continuously

Flash error access - LED3 lights up

Mesh Lib startedsuccessfully - No flashing

Provisioning - No flashing

Un-Provisioning

• Press RESET + SW1 buttons• Release RESET button• Long press SW1 button causes un-

provisioning• Reset the board

LED1 lights up and then keeps flashing duringun-provisioning

Running the demo fromboard

Press SW1 button on any board. It sends thecommand on the node present in thepublication address list

• LED1 on the board toggles (if Subscribedfor the Publish Address)

• LED1 on other boards will also toggle (ifSubscribed for the publish address)

Proxy connection - LED2 lights up

AN5292MAC address management

AN5292 - Rev 1 page 14/36

Page 15: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

5.5 Initialization of application callbacksThe application configuration starts by initializing the callbacks required for the different events and functionalities.These callbacks are used in the BLE mesh library to call the functions based on specific events or the library statemachine. Illustrated in the sample code below:

{ Vendor_WriteLocalDataCb, Vendor_ReadLocalDataCb, Vendor_OnResponseDataCb}; /* Callbacks used by BLE-Mesh library */BLEMesh_SetVendorCbMap(&vendor_cb);

The structure MOBLE_VENDOR_CB_MAP is used to initialize the vendor model for the application implementation.The function BLEMesh_SetVendorCbMap(&vendor_cb); is used to initialize the vendor callbacks in thelibrary.

5.6 Initialization and main application loopThis procedure develops an application for mesh over BLE on the STM32WBx5 platforms:1. Step 1. Call the HAL_Init() API.

This function is used to initialize the HAL Library; it must be the first instruction to be executed in the mainprogram (before calling any other HAL function), it performs the following operations:– Configures the Flash prefetch, instruction and Data caches.– Configures the SysTick to generate a one millisecond interrupt, which is clocked by the MSI (at this

stage, the clock is not yet configured and thus the system is running from the internal MSI at 4 MHz).– Sets NVIC Group Priority to 4.– Calls the HAL_MspInit() callback function defined in user file "stm32wbxx_hal_msp.c" to do the

global low level hardware initialization2. Step 2. Call the Reset_Device() API to reset backup domain and IPCC.3. Step 3. Call the SystemClock_Config() API.

This API configures:– The system clock source– The AHBCLK, APBCLK dividers– The Flash latency– The PLL settings (when required)

4. Step 4. Call the __HAL_RCC_CRC_CLK_ENABLE() API to enable the Peripheral clock.5. Step 5. Call the SystemPower_Config() API to configure the system low power mode.6. Step 6. Call the Config_RTC() API to initialize RTC IP and the Timer Server.7. Step 7. Call the Init_Debug() API to configure UART for debugging trace.8. Step 8. Call the APPE_Init() API to initialize the LEDs, the Buttons and all transport layers.

All transport layer initialization calls the mesh initialization with:– Calls for the Appli_CheckBdMacAddr() API to check the validity of the MAC address.– If the MAC address is not valid, then the firmware is stuck in while(1) loop with the LED continuously

flashing.– Initialization of the hardware callback functions for the BLE hardware.Done by updating

MOBLE_USER_BLE_CB_MAP user_ble_cb = { Appli_BleStackInitCb,Appli_BleSetTxPowerCb,Appli_BleGattConnectionCompleteCb, Appli_BleGattDisconnectionCompleteCb, Appli_BleUnprovisionedIdentifyCb, Appli_BleSetUUIDCb, Appli_BleSetNumberOfElementsCb};

AN5292Initialization of application callbacks

AN5292 - Rev 1 page 15/36

Page 16: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

These APIs are useful to have an application interface for BLE radio initialization and TxPowerconfiguration.

– Initialize GATT connection and disconnection callbacks for the application interface.– BLEMesh_BleHardwareInitCallBack(&user_ble_cb) can be called to complete the

initialization of hardware callbacks.– Initialization of the BLE mesh library by calling BLEMesh_Init(&BLEMeshlib_Init_params).

Done by updating the structure containing mesh library Initialization info data.

const Mesh_Initialization_t BLEMeshlib_Init_params = { bdaddr, &FnParams, &LpnParams, MESH_FEATURES, &DynBufferParam};

In the event of an error, the demo firmware prints a message on the terminal window opened for theVCOM port created by the board’s USB connection and the Appli_LedBlink() API causes the LEDto flashes continuously.

– Several checks can be made◦ Check whether the device has been provisioned or not. A provisioned device has network keys

and other parameters configured in the internal flash memory.◦ Checks can be performed with BLEMesh_IsUnprovisioned() API.If the Node is

unprovisioned, BLEMesh_InitUnprovisionedNode() API initializes it.

If the device is already provisioned , then BLEMesh_InitprovisionedNode() API helps to initializethe device.

– Print the messages to the terminal window for the nodes that are being initialized.The message alsoprints the MAC address assigned to the node.

– Initialize all the 3 models (vendor, generic and lighting model) triggered by theevents.BLEMesh_ModelsInit();

– Check the button state. To initialize the node to the unprovisioned state, hold down the user SW1button.When the unprovisioning SW1 button sequence is detected, the BLEMesh_Unprovision()API erases all the network parameters configured in the internal memory of the device.Onceunprovisioning is complete, the board needs to be reset .

9. Step 9. Process MoBLE and HCI events in while(1) loop.The application must call SCH_Run(), BLEMesh_Process() ,BLEMesh_ModelsProcess() ,Appli_Process() in while(1) loop as frequently as possible.This function calls the MobleStackProcess() internally to process BLE communication.Any application implementation is performed in the state-machine by non-blocking functions with frequentcalls to BLEMesh_Process().

10. Step 10. Check for user-inputs or buttons regularly for any action to take.

AN5292Initialization and main application loop

AN5292 - Rev 1 page 16/36

Page 17: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6 Mesh networking information

6.1 Local and remote conceptRemote actions or operations refer to actions on other network nodes, while local actions refer to the resourceson the same network node.For example, to check the LEDs on the BLE mesh application nodes, click the icon button to invoke the_SetRemoteData action from the application. This causes a Vendor_WriteLocalDataCb action on the node.This is also the case when a group of node LEDs need to be controlled on the board. The LEDs on the addressednodes will toggle when the button on the board is pressed.The same message (for any LEDs action) received by the node requires a WriteLocal action on that node. This isshown in the figure below for the SetRemote/WriteLocal actions on different nodes in the network.

Figure 11. SetRemote/WriteLocal actions

Destination

User-Action to switch on remote node lights

SetRemoteData

Mesh Library

Source

Mesh Library

WriteLocalData

Vendor_WriteLocalDataCb

LED ON

6.2 Acknowledged and unacknowledged messagesBy default, all messages in the mesh network are configured as unacknowledged. The difference betweenacknowledged and unacknowledged messages is the response to the message. A write message to a node mayhave a response in acknowledged communication. Whereas, in unacknowledged communication, the responsemay not be there.The system should be configured to use unacknowledged messages in the mesh network to avoid redundantmessage exchanges over the network, which may impact the system performance.

AN5292Mesh networking information

AN5292 - Rev 1 page 17/36

Page 18: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.3 Provisioning processThe process of configuring a device in a network is called provisioning. It is started by a “Provisioner”, which is aBlueNRG-Mesh application running on the smartphone. The cycle is illustrated in the figure below.

Figure 12. Provisioning process

Unconfigured mesh node

Unprovisioning

Provisioning with data: network key, Key index

Flags, IV index, unicast address

Configuration information

Configured mesh node

Unprovisioned device

The BlueNRG-Mesh mobile application can be installed on the smartphone with BLE 4.0 or higher. Duringinstallation, the application asks for user permission, refer to the appropriate device type BlueNRG-Mesh usermanual for more information (Android™ or iOS™). The steps required for the provisioning are shown in the figurebelow.

AN5292Provisioning process

AN5292 - Rev 1 page 18/36

Page 19: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Figure 13. Provisioning steps

Launch BlueNRG-Mesh Mobile Application

App Prompts to turn ONthe Bluetooth (if not open)

Provisioning Process Starts

1 2 3

4

5

6 ProvisionedNode

Identify Un-provisionedNode

Device UUID ForNode Identification

Provision

7

The provisioning is executed by a GATT connection between the smartphone and the unprovisioned device.

6.4 GATT node connection/disconnectionEach node in the network can connect to a smartphone through the GATT interface.When this connection is established, the node becomes a “proxy”. The proxy has the responsibility of bridging thecommands and responses between the mesh network and the smartphone. The connection status with thesmartphone is managed by the following callbacks

Appli_BleGattConnectionCompleteCb;Appli_BleGattDisconnectionCompleteCb;

These are initialized during the main loop. The smartphone node connection can be determined when there aremany nodes closeby.

AN5292GATT node connection/disconnection

AN5292 - Rev 1 page 19/36

Page 20: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

During provisioning, the GATT connection is established with the node which needs provisionning. If thesmartphone moves out of the range of the proxy node, it establishes a new connection with the next availablenode. LED indication (LED2) is used to show the proxy connection.

6.5 Write command from remote nodeA command from a remote node or from a smartphone to an addressed node invokes a WriteLocalDatacallback.This callback can be used to process the commands or data received within the network. In the application demo,the Vendor_WriteLocalDataCb function is the callback where data or commands are be processed. Thecommand/data flow can be visualised in Figure 11. SetRemote/WriteLocal actions.The response data from the node is sent through SendResponse function.

AN5292Write command from remote node

AN5292 - Rev 1 page 20/36

Page 21: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.6 Read command from a remote nodeA Read command from a remote node or from a smartphone to an addressed node, uses theVendor_ReadLocalDataCb callback. This callback can be used to give the information that a remote node isrequesting. In the application demo, the Vendor_ReadLocalDataCb function is the callback where the readcommands is processed. The command/data flow can be seen in the figure below.

Figure 14. Read command from a remote node

Sensor

DestinationSource

ReadLocalData

ReadAction

User-Action to switch on remote node lights

ReadRemoteData

Mesh Library Mesh Library

ResponseCb

Vendor_ReadLocalDataCb

SendResponse

The response data from the node is sent via the BLEMesh_SendResponse function.

6.7 Application functions and callbacks

6.7.1 User interface and description

Table 4. Appli_LedCtrl

Function

Prototype void Appli_LedCtrl(void)

Behavior description Makes the onboard LED flash. This function is used at power-on andto draw attention to an error condition

Input parameter None

Output parameter Void

AN5292Read command from a remote node

AN5292 - Rev 1 page 21/36

Page 22: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.7.2 User and button interface

Table 5. Appli_ShortButtonPress

Function Description

Prototype static void Appli_ShortButtonPress(void)

Behavior description Call when a button is pressed for short duration

Input parameter Void

Output parameter Void

Table 6. Appli_LongButtonPress

Function Description

Prototype static void Appli_LongButtonPress(void)

Behavior description Call when a button is pressed for long duration

Input parameter Void

Output parameter Void

Table 7. Appli_UpdateButtonState

Function Description

Prototype static void Appli_UpdateButtonState(int isPressed)

Behavior description Update the button status

Input parameter Int isPressed

Output parameter Void

6.7.3 Device BLE configuration type interfaceThis section explains the device configuration functions available to the application developer to be used in thenetwork, as outlined in the following tables.

Table 8. Appli_BleStackInitCb

Function Description

Prototype static void Appli_BleStackInitCb()

Behavior description

This function helps with hardware configuration; mainly theinitialization of the BLE stack based on the structured parametersdefined in BlueNRG_Stack_Init_params.

The user can modify the Low level hardware configuration data forthe device defined in CONFIG_TABLE like LOW_SPEED_SOURCEand HS_STARTUP_TIME, which may depend on the user hardwaredesign.

The Parameters initialize BlueNRG Stack

Input parameter None

Output parameter MOBLE_RESULT status of result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 22/36

Page 23: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 9. Appli_BleSetTxPowerCb

Function Description

Prototype MOBLE_RESULT Appli_BleSetTxPowerCb()

Behavior descriptionThis callback sets the transmission power of BLE radio. This functioncalls aci_hal_set_tx_power_level. By default, the powerlevel is set to +4 dbm

Input parameter None

Output parameter MOBLE_RESULT status of result

Table 10. Appli_BleGattConnectionCompleteCb

Function Description

Prototype void Appli_BleGattConnectionCompleteCb(void)

Behavior descriptionThis function is called when a GATT Connection is detected by thenode. The application can use this callback indicating to the user thatthe node is connected to the smartphone.

Input parameter Void

Output parameter Void

Table 11. Appli_BleGattDisconnectionCompleteCb

Function Description

Prototype void Appli_BleGattDisconnectionCompleteCb(void)

Behavior descriptionThis function is called when a GATT disconnection is detected by thenode. The application can use this callback to indicate to the user thatnode is no longer connected to the smartphone.

Input parameter Void

Output parameter Void

AN5292Application functions and callbacks

AN5292 - Rev 1 page 23/36

Page 24: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.7.4 Vendor model network data communication functionsThe functions explained below help the developer to manage the network data communication and to take theappropriate actions.

Table 12. Vendor_WriteLocalDataCb

Function Description

Prototype

MOBLE_RESULT Vendor_WriteLocalDataCb (MOBLE_ADDRESS peer_addr, MOBLE_ADDRESS dst_peer, MOBLEUINT8 command, MOBLEUINT8 const *data, MOBLEUINT32 length, MOBLEBOOL response)

Behavior description Call back function when an action is required on the node itself

Input parameter

MOBLE_ADDRESS peer_addr: address of the peer.

MOBLE_ADDRESS dst_peer: destination address of thecommand. This can be a group of addresses to which the node issubscribed or the unicast address of element.MOBLEUINT16command: received for the action.

MOBLEUINT8 const *data pointer to the data

MOBLEUINT32 length: length of the data

MOBLEBOOL response: If this is MOBLE_TRUE, the senderexpects an acknowledgement

Output parameter MOBLE_RESULT status of result

Table 13. Vendor_ReadLocalDataCb

Function Description

Prototype

MOBLE_RESULT Vendor_ReadLocalDataCb( MOBLE_ADDRESS peer_addr, MOBLE_ADDRESS dst_peer, MOBLEUINT8 command, MOBLEUINT8 const *data, MOBLEUINT32 length, MOBLEBOOL response)

Behavior description Callback function invoked when data is required from node

Input parameter

MOBLE_ADDRESS peer_addr: address of the peer

MOBLE_ADDRESS dst_peer: destination address of thecommand. This can be a group of addresses to which the node issubscribed or the unicast address of element.

MOBLEUINT16 command : command received for processing

MOBLEUINT8 const *data pointer

MOBLEUINT32 length: data length

MOBLEBOOL response: If this is MOBLE_TRUE, the senderexpects an acknowledgement.

Output parameter MOBLE_RESULT status of result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 24/36

Page 25: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.7.5 MAC address configurationThe following tables list the functions to configure the MAC address.

Table 14. Appli_CheckBdMacAddr

Function Description

Prototype int Appli_CheckBdMacAddr(void)

Behavior description Checks MAC address validity

Input parameter Void

Output parameter int status of result

Table 15. Appli_GetMACFromUniqueNumber

Function Description

Prototype#ifdef INTERNAL_UNIQUE_NUMBER_MACstatic voidAppli_GetMACfromUniqueNumber(void)

Behavior description Reads the OTP BD address of the device and generates the MACaddress from it.

Input parameter Void

Output parameter Void

6.7.6 BLE mesh node configurationThe following tables list the functions to configure the node to be used in the network.

Table 16. BLEMesh_InitUnprovisionedNode

Function Description

Prototype MOBLE_Result BLEMesh_InitUnprovisionedNode(void)

Behavior description Initializes unprovisionned nodes

Input parameter Void

Output parameter MOBLE_RESULT result status

Table 17. BLEMesh_InitProvisionedNode

Function Description

Prototype MOBLE_Result BLEMesh_InitProvisionedNode(void)

Behavior description Initializes provisionned nodes.

Input parameter Void

Output parameter MOBLE_RESULT result status.

AN5292Application functions and callbacks

AN5292 - Rev 1 page 25/36

Page 26: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 18. BLEMesh_GetUnprovisioneState

Function Description

Prototype MOBLEUINT8 BLEMesh_GetUnprovisionedState(void)

Behavior description Gets provisioning process status.

Input parameter Void

Output parameter MOBLEUINT8 result status

Table 19. BLEMesh_GetAddress

Function Description

Prototype MOBLE_ADDRESS BLEMesh_GetAddress (void)

Behavior description Gets node mesh address.

Input parameter Void

Output parameter Node mesh address

Table 20. BLEMesh_GetPublishAddress

Function Description

Prototype MOBLE_ADDRESS BLEMesh_GetPublishAddress(MOBLEUINT8 elementNumber)

Behavior description Gets the node publish address

Input parameter Element number

Output parameter Node publish address

Table 21. BLEMesh_GetSubscriptionAddress

Function Description

Prototype

MOBLE_RESULT BLEMesh_GetSubscriptionAddress( MOBLE_ADDRESS *addressList, MOBLEUINT8 *sizeOfList, MOBLEUINT8 elementNumber)

Behavior description Gets the node subscription addresses

Input parameter SizeofList, elementNumber

Output parameter MOBLE_RESULT subscription address result list status

Table 22. BLEMesh_SetTTL

Function Description

Prototype MOBLE_RESULT BLEMesh_SetTTL (MOBLEUINT8 ttl)

Behavior description Sets the default TTL value

Input parameter MOBLEUINT8 ttl value

Output parameter MOBLE_RESULT result status of

AN5292Application functions and callbacks

AN5292 - Rev 1 page 26/36

Page 27: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 23. BLEMesh_GetTTL

Function Description

Prototype MOBLEUINT8 BLEMesh_GetTTL (void)

Behavior description Get default TTL value

Input parameter Void

Output parameter MOBLEUINT8 Default TTL value

Table 24. BLEMesh_SetNetworkTransmitCount

Function Description

Prototype MOBLE_RESULT BLEMesh_SetNetworkTransmitCount(MOBLEUINT8 count)

Behavior description Set network transmit count value

Input parameter MOBLEUINT8 count, network transmit value. Supported values are1-8

Output parameter MOBLE_RESULT result status

Table 25. BLEMesh_GetNetworkTransmitCount

Function Description

Prototype MOBLE_RESULT BLEMesh_SetNetworkTransmitCount(MOBLEUINT8 count)

Behavior description Set network transmit count value

Input parameter MOBLEUINT8 count, network transmit value. Supported values are1-8

Output parameter MOBLE_RESULT result status

Table 26. BLEMesh_SetRelayRetransmitCount

Function Description

Prototype MOBLE_RESULT BLEMesh_SetRelayRetransmitCount (MOBLEUINT8 count)

Behavior description Set relay retransmit count value

Input parameter MOBLEUINT8 count Relay Retransmit value. Supported values are1-8

Output parameter MOBLE_RESULT status of Result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 27/36

Page 28: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 27. BLEMesh_GetRelayRetransmitCount

Function Description

Prototype MOBLE_RESULT BLEMesh_GetRelayRetransmitCount(void)

Behavior description Get relay retransmit count value

Input parameter Void

Output parameter MOBLEUINT8 Default Relay retransmit Count value

Table 28. BLEMesh_SetHeartbeatCallback

Function Description

Prototype MOBLE_RESULT BLEMesh_SetHeartbeatCallback(MOBLE_HEARTBEAT_CB cb)

Behavior description Set callback for handling heartbeat messages

Input parameter MOBLE_HEARTBEAT_CB cb Callback

Output parameter MOBLE RESULT result status of

Table 29. BLEMesh_SetAttentionTimerCallback

Function Description

Prototype MOBLE_RESULT BLEMesh_SetAttentionTimerCallback (MOBLE_ATTENTION_TIMER_CB cb)

Behavior description Set callback for attention timer. To be used for information duringprovisioning and for health model

Input parameter MOBLE_ATTENTION_TIMER_CB cb Callback

Output parameter MOBLE RESULT result status

6.7.7 BLE mesh library configurationThe following tables list the functions to configure and initialize the ST BLE mesh Library.

Table 30. BLEMesh_Init

Function Description

Prototype MOBLE_RESULT BLEMesh_Init(Const Mesh_Initialization_t* pInit_params)

Behavior description To initialize ST BLE mesh library

Input parameterBdaddr, Features to be supported by library,Low power

node,Friendship & Dynamic Buffer parameters

Output parameter MOBLE RESULT status of Result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 28/36

Page 29: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 31. BLEMesh_GetLibraryVersion

Function Description

Prototype Char * BLEMesh_GetLibraryVersiont(void)

Behavior description To get the latest library version

Input parameter Void

Output parameter string

Table 32. BLEMesh_GetLibrarySubVersion

Function Description

Prototype Char * BLEMesh_GetLibrarySubVersiont(void)

Behavior description To get the latest library sub version

Input parameter Void

Output parameter string

Table 33. BLEMesh_Process

Function Description

Prototype MOBLE_RESULT BLEMesh_Process(void)

Behavior description Mesh task processing function

Input parameter Void

Output parameter MOBLE RESULT result status

Table 34. BLEMesh_SetRemoteData

Function Description

Prototype

MOBLE_RESULT BLEMesh_SetRemoteData( MOBLE_ADDRESS peer, MOBLEUINT8 command, MOBLEUINT8 const * data, MOBLEUINT32 length, MOBLEUINT8 response)

Behavior description Set remote data on the given peer

Input parameter

peer Destination address,

vendor model commands,

Data buffer,

Length of data in bytes,

response (If not '0', used to get the response. If '0', no response)

Output parameter MOBLE RESULT status of Result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 29/36

Page 30: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Table 35. BLEMesh_ReadRemoteData

Function Description

PrototypeMOBLE_RESULT BLEMesh_ReadRemoteData( MOBLE_ADDRESS peer, MOBLEUINT16 command)

Behavior description Read remote data on the given peer

Input parameterpeer Destination address,

vendor model commands

Output parameter MOBLE RESULT status of Result

Table 36. BLEMesh_SendResponse

Function Description

Prototype

MOBLE_RESULT BLEMesh_SendResponse( MOBLE_ADDRESS peer, MOBLEUINT8 status, MOBLEUINT8 const * data, MOBLEUINT32 length)

Behavior description Send response on received packet

Input parameter

peer Destination address,

Status of response,

Data buffer,

Length of data in bytes

Output parameter MOBLE RESULT status of Result

AN5292Application functions and callbacks

AN5292 - Rev 1 page 30/36

Page 31: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Revision history

Table 37. Document revision history

Date Version Changes

22-Mar-2019 1 Initial release.

AN5292

AN5292 - Rev 1 page 31/36

Page 32: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

Contents

1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

2.1 Board interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 P-NUCLEO-WB55 pack board setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.3 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.4 Installing BLE mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Firmware structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

3.1 Root folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.2 Driver folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.3 Project folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.4 Middleware folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Using the BLE mesh demo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

4.1 Using the STM32WBx5 binaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4.2 Using IAR project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5 Firmware initialization and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13

5.1 Setting the transmit power of a node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2 UART interface on the firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.3 MAC address management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.4 Button usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.5 Initialization of application callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.6 Initialization and main application loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

6 Mesh networking information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17

6.1 Local and remote concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6.2 Acknowledged and unacknowledged messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6.3 Provisioning process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.4 GATT node connection/disconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

6.5 Write command from remote node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

6.6 Read command from a remote node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

6.7 Application functions and callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

AN5292Contents

AN5292 - Rev 1 page 32/36

Page 33: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

6.7.1 User interface and description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

6.7.2 User and button interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6.7.3 Device BLE configuration type interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6.7.4 Vendor model network data communication functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

6.7.5 MAC address configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

6.7.6 BLE mesh node configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

6.7.7 BLE mesh library configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31

AN5292Contents

AN5292 - Rev 1 page 33/36

Page 34: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

List of figuresFigure 1. STM35WBx5 board connection with PC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Figure 2. Firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Figure 3. BLE mesh library architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Figure 4. Folders, sub-folders and contents of the package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Figure 5. Root folder structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Figure 6. Driver folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Figure 7. Internal project folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Figure 8. Middleware folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Figure 9. Overview of how to program the binary in the STM32WB55RG MCU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Figure 10. VCOM window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Figure 11. SetRemote/WriteLocal actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Figure 12. Provisioning process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Figure 13. Provisioning steps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Figure 14. Read command from a remote node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

AN5292List of figures

AN5292 - Rev 1 page 34/36

Page 35: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

List of tablesTable 1. Hardware details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Table 2. MAC address management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Table 3. Button usage and LEDs management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Table 4. Appli_LedCtrl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Table 5. Appli_ShortButtonPress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 6. Appli_LongButtonPress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 7. Appli_UpdateButtonState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 8. Appli_BleStackInitCb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 9. Appli_BleSetTxPowerCb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Table 10. Appli_BleGattConnectionCompleteCb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Table 11. Appli_BleGattDisconnectionCompleteCb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Table 12. Vendor_WriteLocalDataCb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Table 13. Vendor_ReadLocalDataCb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Table 14. Appli_CheckBdMacAddr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Table 15. Appli_GetMACFromUniqueNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Table 16. BLEMesh_InitUnprovisionedNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Table 17. BLEMesh_InitProvisionedNode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Table 18. BLEMesh_GetUnprovisioneState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Table 19. BLEMesh_GetAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Table 20. BLEMesh_GetPublishAddress. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Table 21. BLEMesh_GetSubscriptionAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Table 22. BLEMesh_SetTTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Table 23. BLEMesh_GetTTL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Table 24. BLEMesh_SetNetworkTransmitCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Table 25. BLEMesh_GetNetworkTransmitCount. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Table 26. BLEMesh_SetRelayRetransmitCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Table 27. BLEMesh_GetRelayRetransmitCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Table 28. BLEMesh_SetHeartbeatCallback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Table 29. BLEMesh_SetAttentionTimerCallback. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Table 30. BLEMesh_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Table 31. BLEMesh_GetLibraryVersion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 32. BLEMesh_GetLibrarySubVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 33. BLEMesh_Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 34. BLEMesh_SetRemoteData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 35. BLEMesh_ReadRemoteData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Table 36. BLEMesh_SendResponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Table 37. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

AN5292List of tables

AN5292 - Rev 1 page 35/36

Page 36: How to build a Bluetooth® Low Energy mesh application for ... · Introduction Bluetooth® Low Energy Technology (BLE)-mesh connects multiple Low Energy Technology devices with mesh

IMPORTANT NOTICE – PLEASE READ CAREFULLY

STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and improvements to STproducts and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. STproducts are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.

Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design ofPurchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.

Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.

ST and the ST logo are trademarks of ST. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other product or servicenames are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.

© 2019 STMicroelectronics – All rights reserved

AN5292

AN5292 - Rev 1 page 36/36