Bluetooth: Heart Rate Service

The Heart Rate Service sample demonstrates how you can implement the Heart Rate profile using nRF Connect SDK Bare Metal option.

Requirements

The sample supports the following development kits:

The following board variants do not have DFU capabilities:

S115:

Hardware platform

PCA

Board target

nRF54L15 DK

PCA10156

bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice

nRF54L15 DK (emulating nRF54L10)

PCA10156

bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice

nRF54L15 DK (emulating nRF54L05)

PCA10156

bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice

nRF54LM20 DK

PCA10184

bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice

nRF54LS05 DK

PCA10214

bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice

nRF54LS05 DK (emulating nRF54LS05A)

PCA10214

bm_nrf54ls05dk/nrf54ls05a/cpuapp/s115_softdevice

nRF54LV10 DK

PCA10188

bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice

S145:

Hardware platform

PCA

Board target

nRF54L15 DK

PCA10156

bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice

nRF54L15 DK (emulating nRF54L10)

PCA10156

bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice

nRF54L15 DK (emulating nRF54L05)

PCA10156

bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice

nRF54LM20 DK

PCA10184

bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice

nRF54LS05 DK

PCA10214

bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice

nRF54LS05 DK (emulating nRF54LS05A)

PCA10214

bm_nrf54ls05dk/nrf54ls05a/cpuapp/s145_softdevice

nRF54LV10 DK

PCA10188

bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice

Overview

When the application starts, three timers are started. These timers control the generation of various parts of the Heart Rate Measurement characteristic value:

  • Heart Rate

  • RR Interval

  • Sensor Contact Detected

A timer for generating battery measurements is also started.

The sensor measurements are simulated the following way:

  • Heart Rate

  • RR Interval

  • Sensor Contact

  • Battery Level

When notification of Heart Rate Measurement characteristic is enabled, the Heart Rate Measurement, containing the current value for all the components of the Heart Rate Measurement characteristic, is notified each time the Heart Rate measurement timer expires. When notification of Battery Level characteristic is enabled, the Battery Level is notified each time the Battery Level measurement timer expires.

The sample supports bonding with the connected device. The services security configurations are kept open to allow reading the characteristics without bonding with the device.

User interface

Button 1:

Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.

LED 0:

Lit when the device is initialized.

LED 1:

Lit when a device is connected.

Security

The sample integrates Bluetooth: Peer Manager (backed by Bare Metal Zephyr Memory Storage (BM_ZMS) for persistent storage) to support pairing and bonding.

The following security parameters are configured:

Peer Manager security parameters

Parameter

Value

Effect

Bonding

True

Supports storing of pairing information (bonding data).

MITM protection

False

Man-in-the-middle protection not required.

LE Secure Connections

True

Supports LESC pairing.

I/O capabilities

Display only

Determines local I/O capability, actual pairing method depends on negotiation with peer.

This sample configures the following services and their characteristics with these specific operation modes and security levels:

Service

Characteristic

Operation

Required security level

Effect

Heart Rate Service

Heart Rate Measurement

Notify

Open, no security

Any connected device can subscribe and receive periodic heart rate measurement notifications.

Body Sensor Location

Read

Open, no security

Any connected device can read where on the body the sensor is worn.

Device Information Service

All characteristics

Read

Open, no security

Any connected device can read device information such as the manufacturer name and firmware version.

Battery Service

Battery Level

Read/Notify

Open, no security

Any connected device can read the battery level and subscribe to battery level notifications.

See Testing for the pairing and bonding steps.

Building and running

This sample can be found under samples/bluetooth/ble_hrs/ in the Bare Metal folder structure.

For details on how to create, configure, and program a sample, see Getting Started with the samples.

Testing

You can test this sample using nRF Connect for Desktop with the Bluetooth Low Energy app and the Serial Terminal app. Make sure that these are installed before starting the testing procedure.

  1. Compile and program the application.

  2. In the Serial Terminal, observe that the BLE HRS sample initialized message is printed.

  3. Observe that the Advertising as nRF_BM_HRS message is printed. You can configure the advertising name using the CONFIG_SAMPLE_BLE_DEVICE_NAME Kconfig option. For information on how to do this, see Configuring Kconfig.

  4. In nRF Connect for Desktop, scan for advertising devices. If the device is not advertising, reset the board with the Reset Board option in Visual Studio Code or by pressing the reset button on the development kit.

  5. Connect to your device.

    The terminal output in Visual Studio Code indicates Peer connected.

    After having connected, your computer or mobile phone may attempt to pair or bond with your device in order to encrypt the link.

    You may be prompted to enter a passkey as part of the authentication step. If prompted, provide the passkey from the terminal output.

  6. Observe that the services are shown in the connected device and that you can start receiving values for the Heart Rate and the Battery Service by clicking the Play button. Heart Rate notifications are received every second, and Battery Level notifications are received every two seconds.