1. Heart Rate Profile Presentation
Heart Rate Profile (HRP) [1] is a Generic Attribute Profile (GATT) based low energy profile defined by the Bluetooth® Special Interest Group[2]
The HRP, widely used in fitness applications, defines the communication between a GATT-server of a Heart Rate Sensor device, such as a wrist band, and a GATT-client Collector device, such as a smartphone or tablet.
Heart Rate Sensor is the device that measures heart rate data and other information, it can be defined as a GAP peripheral and GATT server implemented with the Heart Rate Service [3]
This wiki page is the description of the Heart Rate Sensor project provided within the STM32CubeWB MCU Package[4]
Bluetooth® LE Heart Rate profile overview |
---|
Header text | Header text | Header text | Header text | Header text | Header text |
---|---|---|---|---|---|
Example | Example | Example | Example | Example | Example |
Example | Example | Example | Example | Example | Example |
Example | Example | Example | Example | Example | Example |
Example | Example | Example | Example | Example | Example |
The table below describes the structure of Heart Rate Sensor services :
Heart Rate Sensor services |
---|
2. Heart Rate Profile Interaction
Heart Rate Profile is a combination of a Heart Rate Collector and a Heart Rate Sensor to connect and exchange data in differents applications.
- The Heart Rate Sensor:
- Measures the heart rate and exposes it via the Heart Rate Service.
- Contains the Device Information Service, which contains information for example about the manufacturer of the device.
- Is the GATT server.
- The Heart Rate Collector:
- Accesses the information exposed by the Heart Rate Sensor and can for example display it to the end user or store it on non-volatile memory for later analysis.
- Is the GATT client.
The GAP - Generic Access Profile defines and manages advertising and connection.
Collector Central device and Sensor Peripheral device |
---|
The GATT - Generic Attribute Profile defines and manages in/out data exchanges.
Collector GATT Client device and Sensor GATT Service device |
---|
Once Bluetooth® LE connection established & notification enabled :
- Heart Rate measurement provided to remote every 1s.
- Connection interval may be change by application.
3. Requirements
3.1. Software and System requirements
Software required are the following (minimum IDEs version) :
- IAR Embedded Workbench for ARM (EWARM) toolchain V8.20.2
- RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.31
- STM32CubeIDE toolchain V1.7.0 [5].
Programmer:
- STM32CubeProgrammer[6] : To flash the board with an already generated binary
3.2. Hardware requirements
P-NUCLEO-WB55 [7] or STM32WB5MM-DK Discovery Kit [8] is necessary to install the application.
Hardware platforms illustration |
---|
|
3.3. Smartphone Application
ST BLE Sensor application (for Android[9], or iOS[10]) or ST BLE ToolBox application (for Android[11], or IOS[12]).
4. STM32WB Heart Rate Sensor Example Description
4.1. Project Directory
The "BLE_HeartRate" application is available by downloading STM32CubeWB MCU Package[13].
Heart Rate project directory |
---|
4.2. Project Description
4.2.1. Structure
Software project structure with the most important parts :
WARNING: Do not modify the files in Middlewares folder
4.2.2. Application Initialization
The different steps of application initialization are described bellow :
4.2.3. GAP & GATT Initialization & Interaction
The Bluetooth LE Heart Rate Sensor Application initialization is done within app_ble.c
- starts the BLE Stack - initialize the device as Peripheral - configure & start Advertising : ADV Parameters, Local Name, UUID - APP_BLE_init()
- call the services controller initialization SVCCTL_Init() - svc_ctl.c
- manages the GAP event - SVCCTL_App_Notification()
- EVT_LE_CONN_COMPLETE - Provides information of the connection interval, slave latency, Supervision timeout
- EVT_LE_CONN_UPDATE_COMPLETE - Provides the new information of the connection
- EVT_DISCONN_COMPLETE - Informs the application about the link disconnection and the reason
- EVT_ENCRYPT_CHANGE - Informs the application weather the link is encrypted
The Services management is done by the service controller - svc_ctl.c
- Calls the Initialization function of all the developed services - SVCCTL_SvcInit()
- Heart Rate service - HRS_Init() - hrs.c
- Device Information service - DIS_Init() - dis.c
- Registers Services Event Handler - SVCCTL_RegisterSvcHandler(...)
- manages events - SVCCTL_UserEvtRx ()- from the BLE Host Stack and redirect them to the services registered - HearRate_Event_Handler() - or gap event handler - SVCCTL_App_Notification
The Heart Rate Service hrs.c manages the specification of the service:
- Service Init - HRS_Init()
- Register Heart Rate Event Handle to Service Controller - SVCCTL_RegisterSvcHandler(HearRate_Event_Handler);
- Initialize Service UUID – add Heart Rate service as Primary services
- Initialize Heart rate Measurement Characteristic
- Initialize Body Sensor Location Characteristic
- Update Heart Rate Measurement Characteristic - HRS_UpdateChar()
- Update Body Sensor Location Characteristic Value - HRS_UpdateChar()
- HeartRate_Event_Handler(void *Event) – manage HCI Vendor Type Event:
- EVT_BLUE_GATT_WRITE_PERMIT_REQ
- Server receives a Write Command
- HR Control Point Char. Value
- Reset Energy Expended command then:
- Send an aci_gatt_write_response() with an OK status.
- Notify HRS application to Reset Energy Expended
- Or Send an aci_gatt_write_response() with an Error.
- EVT_BLUE_GATT_WRITE_PERMIT_REQ
- EVT_BLUE_GATT_ATTRIBUTE_MODIFIED
- HR Measurement Char. Description Value
- ENABLE Or DISABLE Notification
- Notify HRS application of the Measurement Notification
- HR Measurement Char. Description Value
- EVT_BLUE_GATT_ATTRIBUTE_MODIFIED
Heart Rate sensor software module interaction |
---|
4.3. Build and Install
Follow steps described in Bluetooth® LE Build and Install Application page, applying it for BLE_HeartRate project.
5. Heart Rate Collector - Smartphone Application
Once the BLE Heart Rate application installed on the STM32WB platform, launch the ST BLE Sensor smartphone application.
Click on Connect one Device interface:
Heart Rate application interface 1 |
---|
Your device should be visible from this interface, connect to it:
Heart Rate application interface 2 |
---|
Now bpm measurement is displayed in real time.
Heart Rate application interface 3 |
---|
With Discovery Kit Platform, the Heart Rate is also visible from the board LCD screen, and Heart pulse is illustrated:
Heart Rate on DK illustration |
---|
6. References
- ↑ Heart Rate profile specification
- ↑ Bluetooth® SIG
- ↑ Heart Rate service specification
- ↑ STM32CubeWB MCU Package
- ↑ STM32CubeIDE
- ↑ STM32CubeProgrammer Software
- ↑ P-NUCLEO-WB55 package
- ↑ STM32WB5MM-DK board
- ↑ ST BLE Sensor Android application
- ↑ ST BLE Sensor iOS application
- ↑ ST BLE Toolbox Android Application
- ↑ ST BLE Toolbox iOS Application
- ↑ STM32CubeWB MCU Package