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