Skip to content

Commit c407df4

Browse files
sondrepasilz
andcommitted
samples: bluetooth: ble_hrs_peripheral_central: Add sample
Adds the hrs_peripheral_central sample Signed-off-by: Sondre Pettersen <sondre.pettersen@nordicsemi.no> Co-authored-by: Asil Zogby <asil.zogby@nordicsemi.no>
1 parent 75a5fb6 commit c407df4

6 files changed

Lines changed: 1146 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2024 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) 2024 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_Hub"
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: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
.. list-table::
24+
:header-rows: 1
25+
26+
* - Hardware platform
27+
- PCA
28+
- SoftDevice
29+
- Board target
30+
* - `nRF54L15 DK`_
31+
- PCA10156
32+
- S145
33+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
34+
* - `nRF54L15 DK`_ (emulating nRF54L10)
35+
- PCA10156
36+
- S145
37+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
38+
* - `nRF54L15 DK`_ (emulating nRF54L05)
39+
- PCA10156
40+
- S145
41+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
42+
43+
.. group-tab:: MCUboot board variants
44+
45+
The following board variants have DFU capabilities:
46+
47+
.. list-table::
48+
:header-rows: 1
49+
50+
* - Hardware platform
51+
- PCA
52+
- SoftDevice
53+
- Board target
54+
* - `nRF54L15 DK`_
55+
- PCA10156
56+
- S145
57+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
58+
* - `nRF54L15 DK`_ (emulating nRF54L10)
59+
- PCA10156
60+
- S145
61+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
62+
* - `nRF54L15 DK`_ (emulating nRF54L05)
63+
- PCA10156
64+
- S145
65+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
66+
67+
Overview
68+
********
69+
70+
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.
71+
When a peripheral device is connected, the sample starts the service discovery procedure.
72+
If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
73+
If a client connects to this device the client subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications forwarded from the peripheral device.
74+
75+
.. _ble_hrs_peripheral_central_sample_testing:
76+
77+
User interface
78+
**************
79+
80+
Button 0:
81+
Press to disable allow list.
82+
83+
Button 1:
84+
Press to disconnect from the connected peripheral device.
85+
86+
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
87+
88+
Button 2:
89+
Press to disconnect from the connected client device.
90+
91+
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
92+
93+
LED 0:
94+
Lit when the device is initialized.
95+
96+
LED 1:
97+
Lit when a peripheral device is connected.
98+
99+
LED 2:
100+
Lit when a client device is connected.
101+
102+
Building and running
103+
********************
104+
105+
This sample can be found under :file:`samples/bluetooth/ble_hrs_peripheral_central/` in the |BMshort| folder structure.
106+
107+
For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.
108+
109+
Testing
110+
=======
111+
112+
This sample requires three devices to test, one running this sample, another one running the :ref:`ble_hrs_sample` sample, and another running the :ref:`ble_hrs_central_sample`.
113+
114+
Complete the following steps to test the sample:
115+
116+
1. Compile and program the application.
117+
#. In the Serial Terminal, observe that the ``Advertising as nRF_BM_HRS_Hub`` message is printed.
118+
You can configure the advertising name using the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option.
119+
For information on how to do this, see `Configuring Kconfig`_.
120+
#. Observe that the ``BLE HRS Peripheral Central sample initialized`` message is printed.
121+
#. Program the second development kit with the :ref:`ble_hrs_sample` sample.
122+
#. Program the third development kit with the :ref:`ble_hrs_central_sample` sample, set the :kconfig:option:`CONFIG_SAMPLE_TARGET_PERIPHERAL_NAME` Kconfig option to ``nRF_BM_HRS_Peripheral_Central``, and set the :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME` Kconfig option to ``y``.
123+
#. Observe that the ``Scan filter match`` message is printed, followed by ``Connecting to target`` and ``Connected``, this will happen twice, once for each peer.
124+
#. Observe that the ``Heart rate service discovered.`` message is printed.
125+
#. Observe that the device starts receiving heart rate measurement notifications.
126+
#. Observe that the ``Sent heart rate to Central`` message is printed.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 Connection
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+
CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y
24+
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=1
25+
26+
# Button and timer
27+
CONFIG_BM_BUTTONS=y
28+
CONFIG_BM_GPIOTE=y
29+
CONFIG_BM_TIMER=y
30+
31+
# BLE Heart rate client
32+
CONFIG_BLE_HRS_CLIENT=y
33+
34+
# BLE Heart rate server
35+
CONFIG_BLE_HRS=y
36+
37+
# BLE connection parameter
38+
CONFIG_BLE_CONN_PARAMS=y
39+
40+
# BLE database discovery
41+
CONFIG_BLE_DB_DISCOVERY=y
42+
CONFIG_BLE_GATT_QUEUE=y
43+
44+
# BLE scan
45+
CONFIG_BLE_SCAN=y
46+
CONFIG_BLE_SCAN_UUID_COUNT=2
47+
CONFIG_BLE_SCAN_ADDRESS_COUNT=1
48+
CONFIG_BLE_ADV_DATA=y
49+
50+
# Advertising library
51+
CONFIG_BLE_ADV=y
52+
53+
# Peer manager
54+
CONFIG_PEER_MANAGER=y
55+
CONFIG_PM_LESC=y
56+
CONFIG_BM_ZMS=y
57+
58+
CONFIG_BLE_GQ_MAX_CONNECTIONS=2
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
18+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
19+
tags: ci_build
20+
sample.ble_hrs_peripheral_central.logging_w_hwfc_parity:
21+
build_only: true
22+
integration_platforms:
23+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
24+
platform_allow:
25+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
26+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
27+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
28+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
29+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
30+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
31+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice
32+
- bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
33+
- bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
34+
extra_configs:
35+
- CONFIG_BM_UARTE_CONSOLE_UARTE_USE_HWFC=y
36+
- CONFIG_BM_UARTE_CONSOLE_UARTE_PARITY_INCLUDED=y
37+
tags: ci_build

0 commit comments

Comments
 (0)