Bluetooth Fast Pair: Input device

This sample demonstrates how to use Google Fast Pair with the nRF Connect SDK.

Google Fast Pair Service (GFPS) is a standard for pairing Bluetooth® and Bluetooth LE devices with as little user interaction required as possible. Google also provides additional features built upon the Fast Pair standard. For detailed information about supported functionalities, see the official Fast Pair documentation. The software maturity level for the input device use case is outlined in the Google Fast Pair use case support table.

Note

Support for Fast Pair input device use case is also integrated into nRF Desktop. The nRF Desktop is a complete reference application design of Human Interface Device (HID).

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF54L15 PDK

PCA10156

nrf54l15pdk

nrf54l15pdk/nrf54l15/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp/ns nrf5340dk/nrf5340/cpuapp

nRF52 DK

PCA10040

nrf52dk

nrf52dk/nrf52832

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

When built for a board target with the */ns variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

Note

If you use nRF5340 DK, the additional configuration of the network core will be taken from the child_image directory. For more details, see Image-specific variables.

Overview

The sample works as a Fast Pair Provider (one of the Fast Pair roles) and a simple HID multimedia controller. Two buttons are used to control audio volume of the connected Bluetooth Central.

The device can be used to bond with the following devices:

  • Fast Pair Seeker - For example, an Android device. The bonding follows the official Fast Pair Procedure with Bluetooth man-in-the-middle (MITM) protection. The device is linked with the user’s Google account.

  • Bluetooth Central that is not a Fast Pair Seeker - Normal Bluetooth LE bonding is used in this scenario and there is no Bluetooth MITM protection.

Note

The normal Bluetooth LE bonding can be used only if the Fast Pair discoverable advertising mode is selected. In other Fast Pair advertising modes, the device rejects the normal Bluetooth LE bonding.

The sample supports only one simultaneous Bluetooth connection, but it can be bonded with multiple Bluetooth Centrals.

The sample supports both the discoverable and not discoverable Fast Pair advertising. The device keeps the Bluetooth advertising active until a connection is established. While maintaining the connection, the Bluetooth advertising is disabled. The advertising is restarted after disconnection.

See Fast Pair Advertising for detailed information about discoverable and not discoverable advertising.

Fast Pair device registration

Before you can use your device as a Fast Pair Provider, the device model must be registered with Google. This is required to obtain Model ID and Anti-Spoofing Private Key. You can register your own device or use the debug Model ID and Anti-Spoofing Public/Private Key pair obtained by Nordic for development purposes.

Note

To support the input device use case, you must select Input Device option in the Device Type list when registering your device model.

By default, if Model ID and Anti-Spoofing Private Key are not specified, the following debug Fast Pair provider is used:

  • NCS input device - The input device Fast Pair provider:

    • Device Name: NCS input device

    • Model ID: 0x2A410B

    • Anti-Spoofing Private Key (base64, uncompressed): Unoh+nycK/ZJ7k3dHsdcNpiP1SfOy0P/Lx5XixyYois=

    • Device Type: Input Device

    • Notification Type: Fast Pair

    • Data-Only connection: true

    • No Personalized Name: false

See Provisioning the device in the Fast Pair user guide for details.

Important

This is the debug Fast Pair provisioning data obtained by Nordic for the development purposes. Do not use it in production.

To test with the debug mode Model ID, you must configure the Android device to include the debug results while displaying the nearby Fast Pair Providers. For details, see Verifying Fast Pair in the GFPS documentation.

Tip

The sample provides TX power in the Bluetooth advertising data. There is no need to provide the TX power value during device model registration. The device is using only Bluetooth LE, so you must select Skip connecting audio profiles (e.g. A2DP or HFP) option when registering the device.

Seeker device

A Fast Pair Seeker device is required to test the Fast Pair procedure. This is one of the two Fast Pair roles.

For example, you can use an Android device as the Seeker device. To test with a debug mode Model ID, you must configure the Android device to include debug results while displaying the nearby Fast Pair Providers. For details, see Verifying Fast Pair in the GFPS documentation.

Not discoverable advertising requirements

Testing not discoverable advertising requires using at least two Android devices registered to the same Google account. The first one needs to be bonded with Fast Pair Provider before the not discoverable advertising can be detected by the second one.

User interface

The sample supports a simple user interface. You can control the sample using predefined buttons, while LEDs are used to display information.

Buttons

Button 1:

Toggles between three Fast Pair advertising modes:

  • Fast Pair discoverable advertising.

  • Fast Pair not discoverable advertising (with the show UI indication).

  • Fast Pair not discoverable advertising (with the hide UI indication).

The advertising pairing mode (bt_le_adv_prov_adv_state.pairing_mode) is enabled only if the Fast Pair discoverable advertising mode is selected.

Note

The Bluetooth advertising is active only until the Fast Pair Provider connects to a Bluetooth Central. After the connection, you can still switch the advertising modes, but the switch will come into effect only after disconnection. The discoverable advertising is automatically switched to the not discoverable advertising with the show UI indication mode in the following cases:

  • After 10 minutes of active advertising.

  • After a Bluetooth Central successfully pairs.

After the device reaches the maximum number of paired devices (CONFIG_BT_MAX_PAIRED), the device stops looking for new peers. Therefore, the device no longer advertises in the pairing mode (bt_le_adv_prov_adv_state.pairing_mode), and the Fast Pair advertising mode is automatically set to the Fast Pair not discoverable advertising with the hide UI indication on every advertising start.

Button 2:

Increases audio volume of the connected Bluetooth Central.

Button 3:

Removes the Bluetooth bonds. This operation does not clear Fast Pair storage data. The stored Account Keys are not removed.

Button 4:

Decreases audio volume of the connected Bluetooth Central.

LEDs

LED 1:

Keeps blinking with constant interval to indicate that firmware is running.

LED 2:

Depending on the Bluetooth Central connection status:

  • On if the Central is connected over Bluetooth.

  • Off if there is no Central connected.

LED 3:

Depending on the Fast Pair advertising mode setting:

  • On if the device is Fast Pair discoverable.

  • Blinks with 0.5 secs interval if the selected mode is the Fast Pair not discoverable advertising with the show UI indication.

  • Blinks with 1.5 secs interval if the selected mode is the Fast Pair not discoverable advertising with the hide UI indication.

Configuration

See Configuring and building for information about how to permanently or temporarily change the configuration.

Building and running

This sample can be found under samples/bluetooth/fast_pair/input_device in the nRF Connect SDK folder structure.

When built as firmware image for a board target with the */ns variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

When building the sample, you can provide the Fast Pair Model ID (FP_MODEL_ID) and the Fast Pair Anti-Spoofing Key (FP_ANTI_SPOOFING_KEY) as CMake options. If the data is not provided, the sample uses the default provisioning data obtained for the NCS input device (the input device debug Fast Pair provider). See Provisioning the device for detailed guide.

Note

The sample cannot be used without the Fast Pair provisioning data. Programming device with the sample firmware without providing the proper Fast Pair provisioning data would result in assertion failure during boot.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect to the kit that runs this sample with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps. The sample provides Fast Pair debug logs to inform about state of the Fast Pair procedure.

  2. Reset the kit.

  3. Observe that LED 1 is blinking (firmware is running) and LED 3 is lit (device is Fast Pair discoverable). This means that the device is now working as Fast Pair Provider and is advertising.

  4. On the Android device, go to Settings > Google > Devices & sharing (or Device connections, depending on your Android device configuration) > Devices.

  5. Move the Android device close to the Fast Pair Provider that is advertising.

  6. Wait for Android device’s notification about the detected Fast Pair Provider. If you use the Model ID certified by Google, the notification is similar to the following:

    Fast Pair discoverable advertising Android notification

    The device model name and displayed logo depend on the data provided during the device model registration.

    If you use the debug Model ID (for example, the default is NCS input device), the notification is similar to the following:

    Fast Pair discoverable advertising Android notification for debug Model ID.

    The device model name is covered by asterisks and the default Fast Pair logo is displayed instead of the one specified during the device model registration.

  7. Tap the Connect button to initiate the connection and trigger the Fast Pair procedure. After the procedure has completed, the pop-up is updated to inform about successfully completed Fast Pair procedure. LED 2 is lit to indicate that the device is connected with the Bluetooth Central.

    Note

    Some Android devices might disconnect right after the Fast Pair procedure has completed. Go to Settings > Bluetooth and tap on the bonded Fast Pair Provider to reconnect.

    You can now use the connected Fast Pair Provider to control audio volume of the Bluetooth Central.

  8. Press Button 2 to increase the audio volume.

  9. Press Button 4 to decrease the audio volume.

Not discoverable advertising

Testing not discoverable advertising requires using a second Android device that is registered to the same Google account as the first Android device.

Test not discoverable advertising by completing Testing and the following additional steps:

  1. Disconnect the Android device that was used during the default Testing:

    1. Go to Settings > Bluetooth.

    2. Tap on the connected device name to disconnect it.

      Note

      Do not remove Bluetooth bond information related to the Fast Pair Provider.

      After disconnection, the provider automatically switches from the discoverable advertising to the not discoverable advertising with the show UI indication mode. LED 3 is blinking rapidly.

  2. Make sure that the Fast Pair Provider is added to Saved devices on the Android device that was used for Testing:

    1. Go to Settings > Google > Devices & sharing (or Device connections) > Devices > Saved devices.

    2. Verify that the paired device is appearing on the list.

  3. If you want to test the Fast Pair not discoverable advertising with the hide UI indication mode, press Button 1. LED 3 starts blinking slowly.

  4. Wait until the Fast Pair Provider is added to Saved devices on the second Android device:

    1. Go to Settings > Google > Devices & sharing (or Device connections) > Devices > Saved devices. The paired device appears on the list.

    2. If the device does not appear on the list, wait until the data is synced between phones.

  5. Move the second Android device close to the Fast Pair Provider. If you use the Model ID certified by Google and the device is in the show UI indication advertising mode, a notification similar to the following one appears:

    Fast Pair not discoverable advertising Android notification

    If you use the debug Model ID (for example, the default is NCS input device) and the device is in the show UI indication advertising mode, a notification similar to the following one appears:

    Fast Pair not discoverable advertising Android notification for debug Model ID

    The Nordic name is replaced by your own Google account name as this is a default name created by the Fast Pair Seeker during the initial pairing.

    If the device is in the hide UI indication advertising mode, no notification appears. This is because the device advertises, but does not want to be paired with. You can verify that the device is advertising using the nRF Connect for Mobile application.

  6. In the show UI indication mode, when the notification appears, tap on it to trigger the Fast Pair procedure.

  7. Wait for the notification about successful Fast Pair procedure. LED 2 is lit to inform that the device is connected with the Bluetooth Central.

    Note

    Some Android devices might disconnect right after Fast Pair procedure is finished. Go to Settings > Bluetooth and tap on the bonded Fast Pair Provider to reconnect.

    You can now use the connected Fast Pair Provider to control the audio volume of the Bluetooth Central.

  8. Press Button 2 to increase the audio volume.

  9. Press Button 4 to decrease the audio volume.

Personalized Name extension

Testing Personalized Name extension is described in Fast Pair Certification Guidelines for Personalized Name.

Note

To mitigate Android Personalized Name write issues, whenever you change the Personalized Name on an Android phone, perform the following:

  • Write the new Personalized Name.

  • Disconnect the phone from the Fast Pair Provider.

  • Put the Fast Pair Provider in not discoverable advertising mode.

  • The phone reconnects and sends new Personalized Name to the Fast Pair Provider.

Battery Notification extension

Complete the following steps to test Fast Pair Battery Notification extension:

  1. Pair the Fast Pair Provider with at least one Fast Pair Seeker.

  2. Set the Fast Pair Provider in not discoverable advertising mode.

  3. Verify that the Provider is advertising sample battery data using the nRF Connect for Mobile application.

Note

Currently, Android phones have trouble with the Battery Notification extension and sometimes do not display battery information as a user indication.

Dependencies

The sample uses subsystems and firmware components available in the nRF Connect SDK. For details, see the sections below.

Fast Pair GATT Service

This sample uses the Google Fast Pair Service (GFPS) and its dependencies and is configured to meet the requirements of the Fast Pair standard. See Google Fast Pair integration for details about integrating Fast Pair in the nRF Connect SDK.

This sample enables the SB_CONFIG_BT_FAST_PAIR Kconfig option. With this option enabled, the build system calls the Fast Pair provision script, which automatically generates a hexadecimal file containing Fast Pair Model ID and Anti Spoofing Private Key. For more details about enabling Fast Pair for your application, see the Enabling Fast Pair in Kconfig section in the Fast Pair integration guide.

Bluetooth LE advertising data providers

The Bluetooth LE advertising providers are used to generate Bluetooth advertising and scan response data. The sample uses the following providers to generate the advertising packet payload:

The sample uses the following providers to generate the scan response data:

Other

The sample also uses the following secure firmware component: