Skip to content

samples: bluetooth: ble_hrs_peripheral_central: Add sample#721

Open
sondrep wants to merge 3 commits into
nrfconnect:mainfrom
asilz:hrs_peripheral_central
Open

samples: bluetooth: ble_hrs_peripheral_central: Add sample#721
sondrep wants to merge 3 commits into
nrfconnect:mainfrom
asilz:hrs_peripheral_central

Conversation

@sondrep
Copy link
Copy Markdown
Contributor

@sondrep sondrep commented Mar 27, 2026

Adds the hrs_peripheral_central sample.

@github-actions github-actions Bot added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval. labels Mar 27, 2026
@sondrep sondrep force-pushed the hrs_peripheral_central branch 3 times, most recently from be076af to c407df4 Compare March 27, 2026 13:00
@github-actions
Copy link
Copy Markdown

You can find the documentation preview for this PR here.

@sondrep sondrep force-pushed the hrs_peripheral_central branch 3 times, most recently from 6273968 to e92a4af Compare March 27, 2026 14:40
Comment thread samples/bluetooth/ble_hrs_peripheral_central/Kconfig Outdated
@sondrep sondrep force-pushed the hrs_peripheral_central branch from e92a4af to dace255 Compare April 10, 2026 06:25
@sondrep sondrep force-pushed the hrs_peripheral_central branch 2 times, most recently from fc173b4 to 6c42f8e Compare April 17, 2026 14:24
Comment thread subsys/bluetooth/services/ble_hrs/hrs.c Outdated
Comment thread subsys/bluetooth/services/ble_hrs/hrs.c Outdated
Comment thread subsys/bluetooth/services/ble_hrs_client/ble_hrs_client.c Outdated
Comment thread subsys/bluetooth/services/ble_hrs_client/ble_hrs_client.c Outdated
Comment thread subsys/bluetooth/services/ble_hrs_client/ble_hrs_client.c Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
@sondrep sondrep force-pushed the hrs_peripheral_central branch 14 times, most recently from 451dc0d to 4a1fef8 Compare April 24, 2026 10:15
@asilz asilz force-pushed the hrs_peripheral_central branch 5 times, most recently from 763d8bb to ebcd224 Compare May 8, 2026 10:28
@github-actions github-actions Bot removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label May 8, 2026
@asilz asilz force-pushed the hrs_peripheral_central branch 3 times, most recently from 075266e to cb12dff Compare May 8, 2026 10:50
Comment thread subsys/bluetooth/services/ble_hrs/hrs.c Outdated
@anhmolt anhmolt force-pushed the hrs_peripheral_central branch from cb12dff to e918a4f Compare May 18, 2026 17:24
@anhmolt anhmolt self-requested a review May 18, 2026 17:25
@anhmolt anhmolt force-pushed the hrs_peripheral_central branch 2 times, most recently from e918a4f to ea320ab Compare May 18, 2026 17:26
@anhmolt anhmolt dismissed their stale review May 18, 2026 17:27

Suggestions addressed.

@anhmolt anhmolt force-pushed the hrs_peripheral_central branch 3 times, most recently from ecd6c5f to b19702a Compare May 22, 2026 11:44
Comment thread include/bm/bluetooth/services/ble_hrs_client.h Outdated
Comment thread samples/bluetooth/ble_hrs_peripheral_central/src/main.c Outdated
@anhmolt anhmolt force-pushed the hrs_peripheral_central branch 2 times, most recently from 1c5d2c7 to 2375283 Compare May 22, 2026 14:55
Comment on lines +34 to +37
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.
When a peripheral device is connected, the sample starts the service discovery procedure.
If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could use a rewrite. Perhaps something like.

Suggested change
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.
When a peripheral device is connected, the sample starts the service discovery procedure.
If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
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.
This sample acts simultaneously as both a peripheral and central device.
* As a peripheral the sample advertises with the :ref:`lib_ble_service_hrs` UUID (0x180D). 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.
* 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 initiates a connection before starting the service discovery procedure and subscribing to the Heart Rate Measurement characteristic notifications.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote. Please have another look.

Comment on lines +90 to +95
Useful for:
* **Development**: Multiple HRS devices nearby, only want to connect to yours.
* **Production**: Bridge paired with one specific sensor, ignore everything else.
* **Bonded scenarios**: Combine with allow lists for tighter control.
Note: "peripheral" in the option name refers to the *remote* device being scanned
for, not this device's role.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the bullet points sound a bit like marketing content and don't really bring in new technical information. Please remove the bullets but retain the note, this is actually important.

Suggested change
Useful for:
* **Development**: Multiple HRS devices nearby, only want to connect to yours.
* **Production**: Bridge paired with one specific sensor, ignore everything else.
* **Bonded scenarios**: Combine with allow lists for tighter control.
Note: "peripheral" in the option name refers to the *remote* device being scanned
for, not this device's role.
.. note::
``peripheral`` in the option name refers to the *remote* device being scanned for, not this device's role.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed bullet points. Kept the note.

Comment on lines +116 to +133
#. 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.
#. Repeat the same flow with :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME`
(easier, uses the advertised name).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should keep this in the test steps, what do you think @anhmolt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this last step.

Testing
=======

This sample can be tested with three devices,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This sample can be tested with three devices,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

=======

This sample can be tested with three devices,
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`_.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`_.
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`_.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* - Kconfig option
- Matches on
* - :kconfig:option:`CONFIG_SAMPLE_USE_TARGET_PERIPHERAL_NAME`
- Advertised device name (eks: ``"MyDeviceName"``)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Advertised device name (eks: ``"MyDeviceName"``)
- Advertised device name (e.g. ``"MyDeviceName"``)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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.
When a peripheral device is connected, the sample starts the service discovery procedure.
If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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.


Scan filtering options
======================
The sample always scans for devices advertising the Heart Rate Service UUID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The sample always scans for devices advertising the Heart Rate Service UUID
The sample always scans for devices advertising the Heart Rate Service UUID (``0x180D``).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Scan filtering options
======================
The sample always scans for devices advertising the Heart Rate Service UUID
(``0x180D``). Two optional filters can narrow this down further:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(``0x180D``). Two optional filters can narrow this down further:
Two optional filters can narrow this down further:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +90 to +95
Useful for:
* **Development**: Multiple HRS devices nearby, only want to connect to yours.
* **Production**: Bridge paired with one specific sensor, ignore everything else.
* **Bonded scenarios**: Combine with allow lists for tighter control.
Note: "peripheral" in the option name refers to the *remote* device being scanned
for, not this device's role.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the bullet points sound a bit like marketing content and don't really bring in new technical information. Please remove the bullets but retain the note, this is actually important.

Suggested change
Useful for:
* **Development**: Multiple HRS devices nearby, only want to connect to yours.
* **Production**: Bridge paired with one specific sensor, ignore everything else.
* **Bonded scenarios**: Combine with allow lists for tighter control.
Note: "peripheral" in the option name refers to the *remote* device being scanned
for, not this device's role.
.. note::
``peripheral`` in the option name refers to the *remote* device being scanned for, not this device's role.

If this succeeds, the sample subscribes to the Heart Rate Measurement characteristic to receive heart rate notifications.
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.

.. _ble_hrs_peripheral_central_sample_testing:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this label should be moved before 'Building and running'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I see the same in the NUS central and HRS central sample READMEs. I'll fix in #799.

@anhmolt anhmolt force-pushed the hrs_peripheral_central branch from 2375283 to 9595bee Compare May 27, 2026 11:56
sondrep and others added 2 commits May 27, 2026 14:08
Fix connected event handling to ignore connections where the local
device have the central role. Disconnect events should only reset
the ble_hrs stored conn_handle if the disconnect event carries the
same conn_handle.

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>
Add body sensor location event.

Signed-off-by: Sondre Pettersen <sondre.pettersen@nordicsemi.no>
Co-authored-by: Asil Zogby <asil.zogby@nordicsemi.no>
@anhmolt anhmolt force-pushed the hrs_peripheral_central branch from 9595bee to 41adcab Compare May 27, 2026 12:14
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>
@anhmolt anhmolt force-pushed the hrs_peripheral_central branch from 41adcab to 3bf3cce Compare May 27, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants