STM32WB0 Bluetooth® LE – Health Thermometer Sensor

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:

  • STM32CubeWB0 MCU Package[4]
Bluetooth® LE Health Thermometer Profile & STM32WB0
Connectivity WB0 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):
Sends a temperature measurement, and updates related flags.
  • Temperature Type characteristic (MNBS):
One of two methods used to describe the type of temperature measurement in relation to the location on the human body where the temperature was measured.
  • Intermediate Temperature characteristic (INT):
Sends 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 STM32WB0 & ST BLE Toolbox
STM32WBA HT Flow Diagram


1.1. Advertising data

At start up, the Health Thermometer application starts advertising with an interval of approximatively 80-100ms.
Data advertised are composed as follows:

HealthThermometer Advertising packet
Description Length AD Type Value
Device Name 6 0x09 HT_XX (XX: last byte of BD address)
Service UUID 3 0x03 0x1809 (HTS)
Manufacturer Data 15 0xFF See table below
Flags 2 0x01 0x06
(GeneralDiscoverable, BrEdrNotSupported)

The Manufacturer data are encoded following the STMicroelectronics BlueST-SDK v2 for STM32WB0 as described below:

STMicroelectronics Manufacturer Advertising data
Byte Index 0 1 2-3 4 5 6 7 8 9 10-15
Function Length Manufacturer ID Company BlueST SDK Version Device ID Firmware ID Option 1 Option 2 Option 3 Device Address
Value 0x0F 0xFF 0x0030 STMicro 0x02 0x8D Nucleo-WB0 0x8A 0x00 0x00 0x00 0x08E12Axxxx

2. Requirements

2.1. Software and Hardware requirements

For software and hardware requirements, refer to the STM32WB0 Build BLE Project wiki page.

2.2. Compatible collector applications

The STM32CubeWB0 Health Thermometer Sensor project is compatible with the following collectors:

3. STM32WB0 Health Thermometer Sensor example description

3.1. Project directory

The "BLE_HealthThermometer" application is available by downloading STM32CubeWB0 MCU Package[4].

Refer to the How to Build a Bluetooth® LE project wiki page for project directory information.

3.2. Project description

3.2.1. Structure

Software project structure illustrating the most important parts:

Health Thermometer project structure
Connectivity WB0 HealthThermo Archi.png
Connectivity yellow box.png
Main applicative part files
Connectivity dark blue box.png
Services management
Connectivity green box.png
Bluetooth® Low Energy libraries
Connectivity pink box.png
Bluetooth® Low Energy stack modular configuration options and event dispatcher files

WARNING: Do not modify the files in Middlewares folder


3.2.2. Application initialization

The different steps of the application initialization are described below:

Health Thermometer project initialization
Connectivity WB0 HealthThermo Initialization.png
puce1.png
Initialize the system (HAL, clocks, peripherals)
puce2.png
Initialize the RNG, AES block, PKA.
puce3.png
Initialize the Bluetooth® Low Energy Host Stack.
puce4.png
  • Initialize the Bluetooth® Low Energy GATT level.
  • Initialize the Bluetooth® Low Energy GAP level.
puce5.png
  • Initialize the Application/Profile context (Services, Characteristics)
  • Manage Health Thermometer Service notification.
puce6.png
  • Register Service Handler
  • Update services and characteristics

3.2.3. GAP and GATT initialization and interaction

Health Thermometer Sensor software module interaction
Connectivity WB0 HealtThermo module interaction with puces.png
puce3.png

and puce4.png The Bluetooth® Low Energy Health Thermometer application initialization is done within app_ble.c

  • Initialize the Bluetooth® Low Energy stack - initialize the device as peripheral - configure and start advertising: ADV parameters, local name, UUID - APP_BLE_init()
  • Call the services controller initialization BLEEVT_Init() - ble_evt.c.
  • Manage the GAP event - BLEEVT_App_Notification()
    • HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE- provides information of the connection interval, slave latency, supervision timeout
    • HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE- provides the new information of the connection
    • HCI_DISCONNECTION_COMPLETE_EVT_CODE- informs the application about the link disconnection and the reason
puce5.png

Event management is done by the Bluetoooth® Low Energy Event Dispatcher, ble_evt.c.

  • Initialize the number of registered handler - BLEEVT_Init()
  • Manage events - BLE_STACK_Event() - from the Bluetooth® Low Energy Host Stack and redirect them to the event handler - BLEEVT_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_APP_Init() -> HTS_Init() in 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 remote, simulate the temperature measurement every second (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 - BLEEVT_RegisterGattEvtHandler(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 Bluetooth® Low Energy Stack - HTS_EventHandler()
    • ACI_GATT_SRV_WRITE_VSEVT_CODE
      • Reception of a Write Command: Measurement Interval Characterictic Value
        • Send an aci_gatt_srv_resp() with an OK or KO status.
    • ACI_GATT_SRV_ATTRIBUTE_MODIFIED_VSEVT_CODE
      • Reception of an attribute modification - Temperature Measurement Value: ENABLE or DISABLE Indication
        • Notify application of the Measurement Notification:
          notification.EvtOpcode = HTS_TEMM_INDICATE_ENABLED_EVT/HTS_TEMM_INDICATE_DISABLED_EVT; 
          HTS_Notification(&notification);
          
      • Reception of an attribute modification - Intermediate Temperature Value : ENABLE or DISABLE Notification
        • Notify application of the Measurement Notification:
          notification.EvtOpcode = HTS_INT_NOTIFY_ENABLED/HTS_INT_NOTIFY_DISABLED_EVT; 
          HTS_Notification(&notification);
          
      • Reception of an attribute modification - Measurement Interval Value : ENABLE or DISABLE Indication
        • Notify application of the Measurement Notification:
          notification.EvtOpcode = HTS_MEI_INDICATE_ENABLED_EVT/HTS_MEI_INDICATE_DISABLED_EVT; 
          HTS_Notification(&notification);
          

3.3. How to use the Bluetooth® Low Energy Health Thermometer application

Once the Bluetooth® Low Energy Health Thermometer application is installed on the STM32WB0 platform, launch the 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.4. 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_conf.h as described below:

/**
 * Enable or Disable traces in application
 */
#define CFG_DEBUG_APP_TRACE         (1)


Health Thermometer - Initialization phase Connected Phase
==>> Start BLE_Init function
  Success: aci_hal_set_tx_power_level command
  Success: aci_gatt_srv_profile_init command
  Success: aci_gap_init command
  Static Random Bluetooth Address: db:79:9e:4a:b8:6c
  Success: Gap_profile_set_dev_name - Device Name
  Success: Gap_profile_set_appearance - Appearance
  Success: hci_le_set_default_phy command
  Success: aci_gap_set_io_capability command
  Success: aci_gap_set_security_requirements command
  Success: aci_gap_configure_filter_accept_and_resolving_list command
==>> End BLE_Init function

Services and Characteristics creation
Success: aci_gatt_srv_add_service command: DIS
Success: aci_gatt_srv_add_service command: HTS
End of Services and Characteristics creation

==>> Success: aci_gap_set_advertising_configuration
==>> Success: aci_gap_set_advertising_data
==>> Success: aci_gap_set_advertising_enable
>>== hci_le_connection_complete_event - Connection handle: 0x0801
     - Connection established with @:4f:ad:b2:b0:04:3a
     - Connection Interval:   45.00 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_VENDOR_EVT: 0x0C03
>>== HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE
     - Connection Interval:   45.00 ms
     - Connection latency:    0
     - Supervision Timeout:   5000 ms
HCI_LE_META_EVT: 0x08
>>== ACI_GAP_NUMERIC_COMPARISON_VALUE_VSEVT_CODE
     - numeric_value = 801598
     - Hex_value = c3b3e
==>> aci_gap_numeric_comparison_value_confirm_yesno : Success
HCI_LE_META_EVT: 0x09
HCI_EVENT: 0x08
>>== ACI_GAP_PAIRING_COMPLETE_VSEVT_CODE
     - Pairing Success

HCI_VENDOR_EVT: 0x0C01
ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE HTS_TEMM_INDICATE_ENABLED_EVT
ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE HTS_INT_NOTIFY_ENABLED_EVT
HTS_INT_NOTIFY_ENABLED_EVT
HTS_MEI_INDICATE_ENABLED_EVT



4. References

Bluetooth® Low Energy stack v4.x Programming Guidelines (PM0274)