Skip to content

Commit 49fa7cc

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 44fcbcc commit 49fa7cc

8 files changed

Lines changed: 1197 additions & 2 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ No changes since the latest nRF Connect SDK Bare Metal release.
110110
Bluetooth LE samples
111111
--------------------
112112

113-
No changes since the latest nRF Connect SDK Bare Metal release.
113+
* Added the :ref:`ble_hrs_peripheral_central_sample` sample.
114114

115115
NFC samples
116116
-----------
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 "BLE 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 0x78E7F806C5D8
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 # "BLE HRS peripheral central sample"
42+
43+
source "Kconfig.zephyr"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 advertises and scans for devices that advertise with the :ref:`lib_ble_service_hrs` UUID (0x180D) and initiates a connection when a device is found.
35+
When a peripheral device is connected, the sample starts the service discovery procedure.
36+
If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
37+
If a central connects to this device the central subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications forwarded from the peripheral device.
38+
39+
.. _ble_hrs_peripheral_central_sample_testing:
40+
41+
User interface
42+
**************
43+
44+
Button 0:
45+
Press to disable allow list.
46+
47+
When pairing with authentication, press this button to confirm the passkey shown in the COM listener and complete pairing with the other device.
48+
49+
Button 1:
50+
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
51+
52+
When pairing with authentication, press this button to reject the passkey shown in the COM listener to prevent pairing with the other device.
53+
54+
Button 2:
55+
Press to disconnect from the connected peripheral device.
56+
57+
Button 3:
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+
Building and running
70+
********************
71+
72+
This sample can be found under :file:`samples/bluetooth/ble_hrs_peripheral_central/` in the |BMshort| folder structure.
73+
74+
For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.
75+
76+
Scan filtering options
77+
======================
78+
The sample always scans for devices advertising the Heart Rate Service UUID
79+
(``0x180D``). Two optional filters can narrow this down further:
80+
81+
.. list-table::
82+
:header-rows: 1
83+
84+
* - Kconfig option
85+
- Matches on
86+
* - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME`
87+
- Advertised device name (eks: ``"MyDeviceName"``)
88+
* - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR`
89+
- Exact 48-bit Bluetooth address
90+
91+
Useful for:
92+
* **Development**: Multiple HRS devices nearby, only want to connect to yours.
93+
* **Production**: Bridge paired with one specific sensor, ignore everything else.
94+
* **Bonded scenarios**: Combine with allow lists for tighter control.
95+
Note: "peripheral" in the option name refers to the *remote* device being scanned
96+
for, not this device's role.
97+
98+
Testing
99+
=======
100+
101+
This sample can be tested with three devices,
102+
This sample can be tested with three devices, one running this sample, another one running the :ref:`ble_hrs_sample` sample, and a central, for example, a phone or a tablet with `nRF Connect for Mobile`_ or `nRF Toolbox`_.
103+
104+
Complete the following steps to test the sample:
105+
106+
1. Compile and program the application.
107+
#. Observe that the ``BLE HRS Peripheral Central sample initialized`` message is printed.
108+
#. In the Serial Terminal, observe that the ``Advertising as nRF_BM_HRS_bridge`` message is printed.
109+
You can configure the advertising name using the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option.
110+
For information on how to do this, see `Configuring Kconfig`_.
111+
#. Program the second development kit with the :ref:`ble_hrs_sample` sample.
112+
#. Observe that the ``Scan filter match`` message is printed, followed by ``Connecting to target`` and ``Connected``, when connecting to the peripheral device.
113+
#. Observe that the ``Heart rate service discovered`` message is printed.
114+
#. Connect to the device from nRF Connect (the device is advertising as "nRF_BM_HRS_bridge").
115+
#. Observe that the ``Connecting to target`` and ``Connected`` messages are printed when connecting to the central device.
116+
#. Observe that the device starts receiving heart rate measurement notifications and forwarding them to the central.
117+
#. Note the address printed in the log when connecting, e.g:
118+
119+
.. code-block:: console
120+
121+
Connecting to target AA:BB:CC:DD:EE:FF
122+
123+
#. Enable the address filter in Kconfig with the address in little endian:
124+
125+
.. code-block:: cfg
126+
127+
CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR=y
128+
CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR=0xFFEEDDCCBBAA
129+
130+
Rebuild and flash. Confirm the sample still connects to the same peripheral.
131+
#. Change the address to a wrong value, rebuild and flash. Confirm the sample no
132+
longer connects to any peripheral.
133+
#. Repeat the same flow with :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME`
134+
(easier, uses the advertised name).
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)