STM32WBA Bluetooth® LE – Health Thermometer Sensor

Revision as of 13:42, 10 February 2023 by Registered User (→‎How to use)

1. Health Thermometer Profile

Health Thermometer Profile (HTP) [1] is a Generic Attribute Profile (GATT) based low-energy profile defined by the Bluetooth® Special Interest Group[2]
Health Thermometer Profile is a combination of a Health Thermometer Collector and a Health Thermometer Sensor to connect and exchange data in different applications.
The Health Thermometer Sensor:

  • Measures the temperature and exposes it via the Health Thermometer Service[3]
  • Contains the Device Information Service to be identified by the remote device
  • Is the GATT server.

The Health Thermometer Collector:

  • Accesses the information exposed by the Health Thermometer Sensor and can for example display it to the end user or store it on nonvolatile memory for later analysis.
  • Is the GATT client.

This wiki page is the description of the Health Thermometer Sensor project provided within the STM32CubeWBA MCU Package[4]

Bluetooth® LE Health Thermometer Profile & STM32WBA
Connectivity WBA HT Profile.png


The table below describes the structure of Health Thermometer Sensor services:

Bluetooth® LE Health Thermometer Service specification
Service Characteristic Property UUID size
Health Thermometer Service 0x1809
Temperature Measurement Indicate 0x2A1C 13
Temperature Type Read 0x2A1D 1
Intermediate Temperature Notify 0x2A1E 13
Measurement Interval Read,Write,Indicate 0x2A21 2
Device Information Service 0x180A
Manufacturer Name String Read 0x2A29 32
Model Number String Read 0x2A24 32
System ID Read 0x2A23 8

Health Thermometer is exported as a Service

  • Temperature Measurement characteristic (TEMM):
    • send a temperature measurement, and update flags related to these.
  • Temperature Type characteristic (MNBS):
    • is one of two methods that are used to describe the type of temperature measurement in relation to the location on the human body at which the temperature was measured.
  • Intermediate Temperature characteristic (INT):
    • send intermediate temperature values to a device for display purposes while the measurement is in progress.
  • Measurement Interval characteristic (MEI):
    • enables and controls the interval between consecutive temperature measurements.

Device Information (DIS) is exported as a Service

  • Manufacturer Name String characteristic (MANS):
    • name of the manufacturer of the device.
  • Model Number String characteristic (MONS):
    • model number assigned by the device vendor.
  • System ID characteristic (SYID): 
    • structure containing an Organizationally Unique Identifier (OUI) followed by a manufacturer-defined identifier and is unique for each individual instance of the product.
Example of flow diagram between STM32WBA & ST BLE Toolbox
STM32WBA HT Flow Diagram


2. Requirements

2.1. Software and system requirements

The software required are the following (minimum IDEs version):

  • IAR Embedded Workbench for ARM (EWARM) toolchain V??
  • RealView Microcontroller Development Kit (MDK-ARM) toolchain V??
  • STM32CubeIDE toolchain V?? [5].


Programmer:

  • STM32CubeProgrammer[6] : To flash the board with an already generated binary

2.2. Hardware requirements

NUCLEO-WBA5 [7] is necessary to install the application.

Hardware platform illustration
Nucleo-WBA5


2.3. Collector applications compatible

The STM32CubeWBA Health Thermometer Sensor project is compatible with the following collector:

3. STM32WBA Health Thermometer Sensor example description

3.1. Project directory

The "BLE_HealthThermometer" application is available by downloading STM32CubeWBA MCU Package[8].

Heart Rate project directory
Connectivity WBA HealthThermo dir.png

3.2. Project description

3.2.1. Structure

Software project structure with the most important parts:

Heart Rate project structure
Connectivity WBA HealthThermo Archi.png
Connectivity yellow box.png
Main applicative part files
Connectivity blue box.png
Bluetooth® LE Stack API Interface
Connectivity dark blue box.png
Services management
Connectivity green box.png
System commands
Connectivity pink box.png
Transport Layer Interface

WARNING: Do not modify the files in Middlewares folder


3.2.2. Application initialization

The different steps of the application initialization are described below:

Heart Rate project initialization
Connectivity WBA HealthThermo Initialization.png
puce1.png
  • Initialize the system (HAL, clocks, peripherals)
  • Infinite loop for run mode
puce2.png
  • Initialize the BSP, Power Mode, trace, memory manager, NVM
  • Wait for initialization done
puce3.png
  • Initialize the Bluetooth® LE Host Stack
puce4.png
  • Initialize the Bluetooth® LE GATT level
  • Initialize the Bluetooth® LE GAP level
puce5.png
  • Reset the number of registered handler
puce6.png
  • Initialize the context
  • Manage Heart Rate Service notification
puce7.png
  • Register Service Handler
  • Update services and characteristics

3.2.3. GAP and GATT initialization and interaction

puce3.png

and puce4.png The Bluetooth LE Health Thermometer application initialization is done within app_ble.c

  • Initialize the BLE stack - initialize the device as peripheral - configure and start advertising: ADV parameters, local name, UUID - APP_BLE_init()
  • Call the services controller initialization SVCCTL_Init() - svc_ctl.c
  • Manage the GAP event - SVCCTL_App_Notification()
    • HCI_LE_CONNECTION_COMPLETE - provides information of the connection interval, slave latency, supervision timeout
    • HCI_LE_CONNECTION_UPDATE_COMPLETE- provides the new information of the connection
    • HCI_DISCONNECTION_COMPLETE - informs the application about the link disconnection and the reason
puce5.png

The Services management is done by the service controller, svc_ctl.c

  • Initialize the number of registered handler - SVCCTL_SvcInit()
  • Manage events - SVCCTL_UserEvtRx()- from the BLE Host Stack and redirect them to the gap event handler - SVCCTL_App_Notification
puce6.png

The application level of the Health Thermometer is done with hts_app.c:

  • Initialization of the services:
    • Health Thermometer Service - HTS_Init() - hts.c
  • Initialization of the context of the application
  • Receive notification from the Health Thermometer Service - HTS_Notification()
  • When temperature measurement characteristics are enabled by the remote, simulate every 1 s the temperature measure (HTS_APP_Measurement) and increase the energy expended to transfer to the remote device (collector) - HTS_UpdateValue()
puce7.png

The Health Thermometer Service hts.c manages the specification of the service:

  • Service Init - HTS_Init()
    • Register Health Thermometer Event Handle to Service Controller - SVCCTL_RegisterSvcHandler(HTS_EventHandler);
    • Initialize Service UUID – add Health Thermometer service as Primary services
      • Initialize Temperature measurement (TEMM) characteristic
      • Initialize Temperature Type (MNBS) characteristic
      • Initialize Intermediate Temperature (INT) characteristic
      • Initialize Measurement Interval (MEI) characteristic
  • Manage the GATT event from BLE Stack - HTS_EventHandler()
    • ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE
      • Reception of a Write Command: Measurement Interval Characterictic Value
        • Send an aci_gatt_write_response() with an OK or KO status.
    • ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE
      • Reception of an attribute modification - Temperature Measurement Value : ENABLE or DISABLE Indication
        • Notify application of the Measurement Notification - HTS_Notification(HTS_TEMM_INDICATE_ENABLED/DISABLED_EVT)
      • Reception of an attribute modification - Intermediate Temperature Value : ENABLE or DISABLE Notification
        • Notify application of the Measurement Notification - HTS_Notification(HTS_INT_NOTIFY_ENABLED/DISABLED_EVT)
      • Reception of an attribute modification - Measurement Interval Value : ENABLE or DISABLE Indication
        • Notify application of the Measurement Notification - HTS_Notification(HTS_MEI_INDICATE_ENABLED/DISABLED_EVT)


Heart Rate Sensor software module interaction
Connectivity WBA HealtThermo module interaction with puces.png

3.3. Build and install

Follow the steps described in Bluetooth® LE Build and Install Application page, applying them for STM32WBA BLE_HealthThermometer project.

3.4. How to use

Once the BLE Health Thermometer application is installed on the STM32WB platform, launch ST BLE ToolBox smartphone application.

Then, scan and connect the device called HT_XX (where XX is replaced by the last byte of the BD address) to the application.
Once the Bluetooth® LE connection is established and the notification enabled by the smartphone (by clicking on Health Thermometer icon):

  • Intermediate temperature notification is provided to remote every 1 s.
  • Temperature measurement indication is provided to remote every 10 s.

3.5. UART debug trace

Thanks to the debug log via UART interface, it is possible to trace the application project.

To enable the traces within the project, enable them within app_ble.c as described below:

/**
 * When set to 1, the traces are enabled in the BLE services
 */
#define CFG_DEBUG_BLE_TRACE     1
/**
 * Enable or Disable traces in application
 */
#define CFG_DEBUG_APP_TRACE     1
Heart Rate Sensor - Initialization phase Connected Phase
Wireless Firmware version 1.13.0
Wireless Firmware build 5
FUS version 1.2.0
>>== SHCI_SUB_EVT_CODE_READY

>>== WIRELESS_FW_RUNNING 
>>== DBGMCU_GetRevisionID= 2001 

==>> Start Ble_Hci_Gap_Gatt_Init function
  Success: hci_reset command
  Success: aci_hal_write_config_data command - CONFIG_DATA_PUBADDR_OFFSET
  Public Bluetooth Address: 00:80:e1:26:ff:eb
  Success: aci_hal_write_config_data command - CONFIG_DATA_IR_OFFSET
  Success: aci_hal_write_config_data command - CONFIG_DATA_ER_OFFSET
  Success: aci_hal_set_tx_power_level command
  Success: aci_gatt_init command
  Success: aci_gap_init command
  Success: hci_le_set_default_phy command
  Success: aci_gap_set_io_capability command
  Success: aci_gap_set_authentication_requirement command
  Success: aci_gap_configure_whitelist command
==>> End Ble_Hci_Gap_Gatt_Init function

Device Information Service (DIS) is added Successfully 000C
Manufacturer Name Characteristic Added Successfully  000D 
Model Number String Characteristic Added Successfully  000F 
Heart Rate Service (HRS) is added Successfully 0011
Heart Rate Measurement Characteristic Added Successfully  0012 
Sensor Location Characteristic Added Successfully  0015 
Control Point Characteristic Added Successfully  0017 
==>> aci_gap_set_discoverable - Success
==>> Success: Start Fast Advertising
>>== HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE - Connection handle: 0x801
     - Connection established with Central: @:72:16:9d:9e:d5:8e
     - Connection Interval:   48.75 ms
     - Connection latency:    0
     - Supervision Timeout: 5000 ms

>>== HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE
     - Connection Interval:   7.50 ms
     - Connection latency:    0
     - Supervision Timeout: 5000 ms

>>== HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE
     - Connection Interval:   48.75 ms
     - Connection latency:    0
     - Supervision Timeout: 5000 ms

ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE HRS_NOTIFICATION_ENABLED
==>> hci_le_read_phy - Success
==>> PHY Param  TX= 1, RX= 1 
==>> hci_le_set_phy PHY Param  TX= 2, RX= 2 - Success

==>> HCI_LE_PHY_UPDATE_COMPLETE_SUBEVT_CODE - status ok 
==>> hci_le_read_phy - Success 
==>> PHY Param  TX= 2, RX= 2

4. References