Skip to content

Commit 9595bee

Browse files
sondrepanhmoltasilz
committed
samples: bluetooth: add ble_hrs_peripheral_central sample
Add the hrs_peripheral_central sample. Co-authored-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no> Co-authored-by: Asil Zogby <asil.zogby@nordicsemi.no> Signed-off-by: Sondre Pettersen <sondre.pettersen@nordicsemi.no>
1 parent ea24aba commit 9595bee

7 files changed

Lines changed: 1190 additions & 0 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Peripheral samples
114114
Bluetooth LE samples
115115
--------------------
116116

117+
* Added the :ref:`ble_hrs_peripheral_central_sample` sample.
118+
117119
* :ref:`ble_nus_central_sample` sample:
118120

119121
* Fixed the disconnect button handler to only disconnect on button press, and not on button release.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(ble_hrs_peripheral_central)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "Bluetooth LE HRS peripheral central sample"
8+
9+
config SAMPLE_BLE_DEVICE_NAME
10+
string "Device name"
11+
default "nRF_BM_HRS_bridge"
12+
13+
config SAMPLE_USE_TARGET_PERIPHERAL_NAME
14+
bool "Use target peripheral name"
15+
default y
16+
17+
if SAMPLE_USE_TARGET_PERIPHERAL_NAME
18+
19+
config SAMPLE_TARGET_PERIPHERAL_NAME
20+
string "Target peripheral name"
21+
default "nRF_BM_HRS"
22+
23+
endif # SAMPLE_USE_TARGET_PERIPHERAL_NAME
24+
25+
config SAMPLE_USE_TARGET_PERIPHERAL_ADDR
26+
bool "Use target peripheral address"
27+
28+
if SAMPLE_USE_TARGET_PERIPHERAL_ADDR
29+
30+
config SAMPLE_TARGET_PERIPHERAL_ADDR
31+
hex "Target peripheral address"
32+
range 0x0 0xffffffffffff
33+
default 0xD627FDA7AE54
34+
35+
endif # SAMPLE_USE_TARGET_PERIPHERAL_ADDR
36+
37+
module=SAMPLE_BLE_HRS_PERIPHERAL_CENTRAL
38+
module-str=BLE Heart Rate Peripheral Central Service Sample
39+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
40+
41+
endmenu # "Bluetooth LE HRS peripheral central sample"
42+
43+
source "Kconfig.zephyr"
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.. _ble_hrs_peripheral_central_sample:
2+
3+
Bluetooth: Heart Rate Service Peripheral Central
4+
################################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Heart Rate Service Peripheral Central sample demonstrates how you can implement the Heart Rate profile as a server and client using |BMlong|.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. tabs::
18+
19+
.. group-tab:: Simple board variants
20+
21+
The following board variants do **not** have DFU capabilities:
22+
23+
.. include:: /includes/supported_boards_all_non-mcuboot_variants_s145.txt
24+
25+
.. group-tab:: MCUboot board variants
26+
27+
The following board variants have DFU capabilities:
28+
29+
.. include:: /includes/supported_boards_all_mcuboot_variants_s145.txt
30+
31+
Overview
32+
********
33+
34+
This sample acts simultaneously as both a peripheral and a central device.
35+
36+
* As a peripheral it advertises with the :ref:`lib_ble_service_hrs` UUID (0x180D).
37+
A central can connect to this device and subscribe to the Heart Rate Measurement characteristic to receive heart rate notifications.
38+
* As a central the sample scans for other devices that advertise with the :ref:`lib_ble_service_hrs` UUID (0x180D).
39+
When a device is found, it connects and starts service discovery.
40+
If the heart rate service is found, it subscribes to receive heart rate notifications that will be forwarded to a connected central device.
41+
42+
User interface
43+
**************
44+
45+
Button 0:
46+
Press to disable allow list.
47+
48+
When pairing with authentication, press this button to confirm the passkey shown in the COM listener and complete pairing with the other device.
49+
50+
Button 1:
51+
Press to disconnect from the connected peripheral device.
52+
53+
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
54+
55+
When pairing with authentication, press this button to reject the passkey shown in the COM listener to prevent pairing with the other device.
56+
57+
Button 2:
58+
Press to disconnect from the connected central device.
59+
60+
LED 0:
61+
Lit when the device is initialized.
62+
63+
LED 1:
64+
Lit when connected to a peripheral device.
65+
66+
LED 2:
67+
Lit when connected to a central device.
68+
69+
.. _ble_hrs_peripheral_central_sample_testing:
70+
71+
Building and running
72+
********************
73+
74+
This sample can be found under :file:`samples/bluetooth/ble_hrs_peripheral_central/` in the |BMshort| folder structure.
75+
76+
For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.
77+
78+
Scan filtering options
79+
======================
80+
81+
The sample always scans for devices advertising the Heart Rate Service UUID (``0x180D``).
82+
Two optional filters can narrow this down further:
83+
84+
.. list-table::
85+
:header-rows: 1
86+
87+
* - Kconfig option
88+
- Matches on
89+
* - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME`
90+
- Advertised device name (e.g. ``"MyDeviceName"``)
91+
* - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR`
92+
- Exact 48-bit Bluetooth address
93+
94+
.. note::
95+
96+
Use of ``peripheral`` in the option name refers to the *remote* device being scanned for, not this device's role.
97+
98+
Testing
99+
=======
100+
101+
This sample can be tested with three devices:
102+
103+
* A device running this sample.
104+
* A device running the :ref:`ble_hrs_sample` sample.
105+
* A central device, for example, a phone or a tablet with `nRF Connect for Mobile`_ or `nRF Toolbox`_.
106+
107+
Complete the following steps to test the sample:
108+
109+
1. Compile and program the application.
110+
#. Observe that the ``BLE HRS Peripheral Central sample initialized`` message is printed.
111+
#. In the Serial Terminal, observe that the ``Advertising as nRF_BM_HRS_bridge`` message is printed.
112+
You can configure the advertising name using the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option.
113+
For information on how to do this, see `Configuring Kconfig`_.
114+
#. Program the second development kit with the :ref:`ble_hrs_sample` sample.
115+
#. Observe that the ``Scan filter match`` message is printed, followed by ``Connecting to target`` and ``Connected``, when connecting to the peripheral device.
116+
#. Observe that the ``Heart rate service discovered`` message is printed.
117+
#. Connect to the device from nRF Connect (the device is advertising as "nRF_BM_HRS_bridge").
118+
#. Observe that the ``Connecting to target`` and ``Connected`` messages are printed when connecting to the central device.
119+
#. Observe that the device starts receiving heart rate measurement notifications and forwarding them to the central.
120+
#. Note the address printed in the log when connecting, e.g:
121+
122+
.. code-block:: console
123+
124+
Connecting to target AA:BB:CC:DD:EE:FF
125+
126+
#. Enable the address filter in Kconfig with:
127+
128+
.. code-block:: cfg
129+
130+
CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR=y
131+
CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR=0xAABBCCDDEEFF
132+
133+
Rebuild and flash. Confirm the sample still connects to the same peripheral.
134+
#. Change the address to a wrong value, rebuild and flash. Confirm the sample no
135+
longer connects to any peripheral.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Logging
2+
CONFIG_LOG=y
3+
CONFIG_LOG_BACKEND_BM_UARTE=y
4+
5+
# SoftDevice
6+
CONFIG_SOFTDEVICE=y
7+
8+
# SoftDevice handler link counts
9+
CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT=2
10+
CONFIG_NRF_SDH_BLE_CENTRAL_LINK_COUNT=1
11+
12+
# Enable RNG
13+
CONFIG_NRF_SECURITY=y
14+
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
15+
CONFIG_PSA_WANT_GENERATE_RANDOM=y
16+
17+
# Enable Crypto functionality required by LE Secure Connections pairing (ECDH over NIST P-256)
18+
CONFIG_PSA_WANT_ALG_ECDH=y
19+
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y
20+
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT=y
21+
CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y
22+
CONFIG_PSA_WANT_ECC_SECP_R1_256=y
23+
# PSA key storage: one slot per concurrent pairing
24+
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y
25+
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=2
26+
27+
# Button and timer
28+
CONFIG_BM_BUTTONS=y
29+
CONFIG_BM_GPIOTE=y
30+
CONFIG_BM_TIMER=y
31+
32+
# BLE Heart rate client
33+
CONFIG_BLE_HRS_CLIENT=y
34+
35+
# BLE Heart rate server
36+
CONFIG_BLE_HRS=y
37+
38+
# BLE BAS client
39+
CONFIG_BLE_BAS_CLIENT=y
40+
41+
# BLE BAS server
42+
CONFIG_BLE_BAS=y
43+
44+
# BLE connection parameter
45+
CONFIG_BLE_CONN_PARAMS=y
46+
47+
# BLE database discovery
48+
CONFIG_BLE_DB_DISCOVERY=y
49+
CONFIG_BLE_GATT_QUEUE=y
50+
51+
# BLE scan
52+
CONFIG_BLE_SCAN=y
53+
CONFIG_BLE_SCAN_UUID_COUNT=2
54+
CONFIG_BLE_SCAN_ADDRESS_COUNT=1
55+
CONFIG_BLE_ADV_DATA=y
56+
57+
# Advertising library
58+
CONFIG_BLE_ADV=y
59+
CONFIG_BLE_ADV_RESTART_ON_DISCONNECT=n
60+
61+
# Peer manager
62+
CONFIG_PEER_MANAGER=y
63+
CONFIG_PM_LESC=y
64+
CONFIG_BM_ZMS=y
65+
66+
# GATT queue: one queue per concurrent connection
67+
CONFIG_BLE_GQ_MAX_CONNECTIONS=2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sample:
2+
name: Bluetooth LE Heart Rate Peripheral Central Service Sample
3+
tests:
4+
sample.ble_hrs_peripheral_central:
5+
build_only: true
6+
integration_platforms:
7+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
8+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
9+
platform_allow:
10+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
11+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
12+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
13+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
14+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
15+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
16+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice
17+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot
18+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
19+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice/mcuboot
20+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
21+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice/mcuboot
22+
tags: ci_build

0 commit comments

Comments
 (0)