-
Notifications
You must be signed in to change notification settings - Fork 39
samples: bluetooth: ble_hrs_peripheral_central: Add sample #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sondrep
wants to merge
3
commits into
nrfconnect:main
Choose a base branch
from
asilz:hrs_peripheral_central
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
samples/bluetooth/ble_hrs_peripheral_central/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # | ||
| # Copyright (c) 2026 Nordic Semiconductor ASA | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| # | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
|
|
||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(ble_hrs_peripheral_central) | ||
|
|
||
| target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # | ||
| # Copyright (c) 2026 Nordic Semiconductor ASA | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| # | ||
|
|
||
| menu "Bluetooth LE HRS peripheral central sample" | ||
|
|
||
| config SAMPLE_BLE_DEVICE_NAME | ||
| string "Device name" | ||
| default "nRF_BM_HRS_bridge" | ||
|
|
||
| config SAMPLE_USE_TARGET_PERIPHERAL_NAME | ||
| bool "Use target peripheral name" | ||
| default y | ||
|
|
||
| if SAMPLE_USE_TARGET_PERIPHERAL_NAME | ||
|
|
||
| config SAMPLE_TARGET_PERIPHERAL_NAME | ||
| string "Target peripheral name" | ||
| default "nRF_BM_HRS" | ||
|
|
||
| endif # SAMPLE_USE_TARGET_PERIPHERAL_NAME | ||
|
|
||
| config SAMPLE_USE_TARGET_PERIPHERAL_ADDR | ||
| bool "Use target peripheral address" | ||
|
|
||
| if SAMPLE_USE_TARGET_PERIPHERAL_ADDR | ||
|
|
||
| config SAMPLE_TARGET_PERIPHERAL_ADDR | ||
| hex "Target peripheral address" | ||
| range 0x0 0xffffffffffff | ||
| default 0xD627FDA7AE54 | ||
|
|
||
| endif # SAMPLE_USE_TARGET_PERIPHERAL_ADDR | ||
|
|
||
| module=SAMPLE_BLE_HRS_PERIPHERAL_CENTRAL | ||
| module-str=BLE Heart Rate Peripheral Central Service Sample | ||
| source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" | ||
|
|
||
| endmenu # "Bluetooth LE HRS peripheral central sample" | ||
|
|
||
| source "Kconfig.zephyr" |
135 changes: 135 additions & 0 deletions
135
samples/bluetooth/ble_hrs_peripheral_central/README.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| .. _ble_hrs_peripheral_central_sample: | ||
|
|
||
| Bluetooth: Heart Rate Service Peripheral Central | ||
| ################################################ | ||
|
|
||
| .. contents:: | ||
| :local: | ||
| :depth: 2 | ||
|
|
||
| The Heart Rate Service Peripheral Central sample demonstrates how you can implement the Heart Rate profile as a server and client using |BMlong|. | ||
|
|
||
| Requirements | ||
| ************ | ||
|
|
||
| The sample supports the following development kits: | ||
|
|
||
| .. tabs:: | ||
|
|
||
| .. group-tab:: Simple board variants | ||
|
|
||
| The following board variants do **not** have DFU capabilities: | ||
|
|
||
| .. include:: /includes/supported_boards_all_non-mcuboot_variants_s145.txt | ||
|
|
||
| .. group-tab:: MCUboot board variants | ||
|
|
||
| The following board variants have DFU capabilities: | ||
|
|
||
| .. include:: /includes/supported_boards_all_mcuboot_variants_s145.txt | ||
|
|
||
| Overview | ||
| ******** | ||
|
|
||
| This sample acts simultaneously as both a peripheral and a central device. | ||
|
|
||
| * As a peripheral it advertises with the :ref:`lib_ble_service_hrs` UUID (0x180D). | ||
| A central can connect to this device and subscribe to the Heart Rate Measurement characteristic to receive heart rate notifications. | ||
| * As a central the sample scans for other devices that advertise with the :ref:`lib_ble_service_hrs` UUID (0x180D). | ||
| When a device is found, it connects and starts service discovery. | ||
| If the heart rate service is found, it subscribes to receive heart rate notifications that will be forwarded to a connected central device. | ||
|
|
||
| User interface | ||
| ************** | ||
|
|
||
| Button 0: | ||
| Press to disable allow list. | ||
|
|
||
| When pairing with authentication, press this button to confirm the passkey shown in the COM listener and complete pairing with the other device. | ||
|
|
||
| Button 1: | ||
| Press to disconnect from the connected peripheral device. | ||
|
|
||
| Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device. | ||
|
|
||
| When pairing with authentication, press this button to reject the passkey shown in the COM listener to prevent pairing with the other device. | ||
|
|
||
| Button 2: | ||
| Press to disconnect from the connected central device. | ||
|
|
||
| LED 0: | ||
| Lit when the device is initialized. | ||
|
|
||
| LED 1: | ||
| Lit when connected to a peripheral device. | ||
|
|
||
| LED 2: | ||
| Lit when connected to a central device. | ||
|
|
||
| .. _ble_hrs_peripheral_central_sample_testing: | ||
|
|
||
| Building and running | ||
| ******************** | ||
|
|
||
| This sample can be found under :file:`samples/bluetooth/ble_hrs_peripheral_central/` in the |BMshort| folder structure. | ||
|
|
||
| For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`. | ||
|
|
||
|
PizzaAllTheWay marked this conversation as resolved.
|
||
| Scan filtering options | ||
| ====================== | ||
|
|
||
| The sample always scans for devices advertising the Heart Rate Service UUID (``0x180D``). | ||
| Two optional filters can narrow this down further: | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Kconfig option | ||
| - Matches on | ||
| * - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME` | ||
| - Advertised device name (e.g. ``"MyDeviceName"``) | ||
| * - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR` | ||
| - Exact 48-bit Bluetooth address | ||
|
|
||
| .. note:: | ||
|
|
||
| Use of ``peripheral`` in the option name refers to the *remote* device being scanned for, not this device's role. | ||
|
|
||
| Testing | ||
| ======= | ||
|
|
||
| This sample can be tested with three devices: | ||
|
|
||
| * A device running this sample. | ||
| * A device running the :ref:`ble_hrs_sample` sample. | ||
| * A central device, for example, a phone or a tablet with `nRF Connect for Mobile`_ or `nRF Toolbox`_. | ||
|
|
||
| Complete the following steps to test the sample: | ||
|
|
||
| 1. Compile and program the application. | ||
| #. Observe that the ``BLE HRS Peripheral Central sample initialized`` message is printed. | ||
| #. In the Serial Terminal, observe that the ``Advertising as nRF_BM_HRS_bridge`` message is printed. | ||
| You can configure the advertising name using the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option. | ||
| For information on how to do this, see `Configuring Kconfig`_. | ||
| #. Program the second development kit with the :ref:`ble_hrs_sample` sample. | ||
| #. Observe that the ``Scan filter match`` message is printed, followed by ``Connecting to target`` and ``Connected``, when connecting to the peripheral device. | ||
| #. Observe that the ``Heart rate service discovered`` message is printed. | ||
| #. Connect to the device from nRF Connect (the device is advertising as "nRF_BM_HRS_bridge"). | ||
| #. Observe that the ``Connecting to target`` and ``Connected`` messages are printed when connecting to the central device. | ||
| #. Observe that the device starts receiving heart rate measurement notifications and forwarding them to the central. | ||
|
PizzaAllTheWay marked this conversation as resolved.
|
||
| #. Note the address printed in the log when connecting, e.g: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| Connecting to target AA:BB:CC:DD:EE:FF | ||
|
|
||
| #. Enable the address filter in Kconfig with: | ||
|
|
||
| .. code-block:: cfg | ||
|
|
||
| CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_ADDR=y | ||
| CONFIG_SAMPLE_TARGET_PERIPHERAL_ADDR=0xAABBCCDDEEFF | ||
|
|
||
| Rebuild and flash. Confirm the sample still connects to the same peripheral. | ||
| #. Change the address to a wrong value, rebuild and flash. Confirm the sample no | ||
| longer connects to any peripheral. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Logging | ||
| CONFIG_LOG=y | ||
| CONFIG_LOG_BACKEND_BM_UARTE=y | ||
|
|
||
| # SoftDevice | ||
| CONFIG_SOFTDEVICE=y | ||
|
|
||
| # SoftDevice handler link counts | ||
| CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT=2 | ||
| CONFIG_NRF_SDH_BLE_CENTRAL_LINK_COUNT=1 | ||
|
|
||
| # Enable RNG | ||
| CONFIG_NRF_SECURITY=y | ||
| CONFIG_MBEDTLS_PSA_CRYPTO_C=y | ||
| CONFIG_PSA_WANT_GENERATE_RANDOM=y | ||
|
PizzaAllTheWay marked this conversation as resolved.
|
||
|
|
||
| # Enable Crypto functionality required by LE Secure Connections pairing (ECDH over NIST P-256) | ||
| CONFIG_PSA_WANT_ALG_ECDH=y | ||
| CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE=y | ||
| CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT=y | ||
| CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT=y | ||
| CONFIG_PSA_WANT_ECC_SECP_R1_256=y | ||
| # PSA key storage: one slot per concurrent pairing | ||
| CONFIG_MBEDTLS_PSA_STATIC_KEY_SLOTS=y | ||
| CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=2 | ||
|
|
||
| # Button and timer | ||
| CONFIG_BM_BUTTONS=y | ||
| CONFIG_BM_GPIOTE=y | ||
| CONFIG_BM_TIMER=y | ||
|
|
||
| # BLE Heart rate client | ||
| CONFIG_BLE_HRS_CLIENT=y | ||
|
|
||
| # BLE Heart rate server | ||
| CONFIG_BLE_HRS=y | ||
|
|
||
| # BLE BAS client | ||
| CONFIG_BLE_BAS_CLIENT=y | ||
|
|
||
| # BLE BAS server | ||
| CONFIG_BLE_BAS=y | ||
|
|
||
| # BLE connection parameter | ||
| CONFIG_BLE_CONN_PARAMS=y | ||
|
|
||
| # BLE database discovery | ||
| CONFIG_BLE_DB_DISCOVERY=y | ||
| CONFIG_BLE_GATT_QUEUE=y | ||
|
|
||
| # BLE scan | ||
| CONFIG_BLE_SCAN=y | ||
| CONFIG_BLE_SCAN_UUID_COUNT=2 | ||
| CONFIG_BLE_SCAN_ADDRESS_COUNT=1 | ||
| CONFIG_BLE_ADV_DATA=y | ||
|
|
||
| # Advertising library | ||
| CONFIG_BLE_ADV=y | ||
| CONFIG_BLE_ADV_RESTART_ON_DISCONNECT=n | ||
|
|
||
| # Peer manager | ||
| CONFIG_PEER_MANAGER=y | ||
| CONFIG_PM_LESC=y | ||
| CONFIG_BM_ZMS=y | ||
|
|
||
| # GATT queue: one queue per concurrent connection | ||
| CONFIG_BLE_GQ_MAX_CONNECTIONS=2 | ||
|
PizzaAllTheWay marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| sample: | ||
| name: Bluetooth LE Heart Rate Peripheral Central Service Sample | ||
| tests: | ||
| sample.ble_hrs_peripheral_central: | ||
| build_only: true | ||
| integration_platforms: | ||
| - bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice | ||
| - bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot | ||
| platform_allow: | ||
| - bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice | ||
| - bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot | ||
| - bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice | ||
| - bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot | ||
| - bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice | ||
| - bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot | ||
| - bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice | ||
| - bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot | ||
| - bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice | ||
| - bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice/mcuboot | ||
| - bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice | ||
|
anhmolt marked this conversation as resolved.
|
||
| - bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice/mcuboot | ||
| tags: ci_build | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.