nRF5 SDK v12.1.0
Experimental: HID Keyboard Application with BLE pairing using NFC
This information applies to the nRF52 Series only.
This example requires the following SoftDevice: S132

Important: Before you run this example, make sure to program the SoftDevice.

This example is based on the BLE Peripheral HID Keyboard Application example. It implements the HID over GATT profile for keyboard and enables pairing from a BLE Central device using the NFC interface. To do the pairing, it uses the NFC tag module that is one of the nRF52 peripherals and the NFC antenna that is delivered with the nRF52 Development Kit.

The application shows the usage of the BLE pairing message generation module. It includes the same services that are present in the original HID Keyboard Application example. See the documentation for that example for details. The following description presents only the differences from the original example.

When the application starts, it initializes and starts the NFCT peripheral, which is used for pairing. The application does not start advertising immediately, but only when the NFC tag is read by an NFC polling device, for example a smartphone or a tablet with NFC support. The message that the tag sends to the NFC device contains data required to initiate pairing. To start the NFC data transfer, the NFC device must touch the NFC antenna that is connected to the nRF52 Development Kit.

After reading the tag, the device can pair with the nRF52 device which is advertising. After connecting, the example application behaves the same way as the original HID Keyboard example. Reading the NFC tag again when the application is in a connected state does not start advertising. When the pairing is successful, new NFC tag data is configured to display a text message: "Already paired!". When the connection is lost, advertising does not restart automatically. To restart advertising, the NFC tag must be read again or the wake up button must be pressed. Then advertising with whitelist starts, so only the paired peer can connect. Reading the tag will not trigger pairing. To pair with a different device, remove bonding information by pressing Button 2 on application startup. When there is no bonding information, the NFC tag data is configured to trigger pairing again, using a BLE pairing message.

Only one NFC transfer is required to connect to the nRF52 device and get the HID services using the HID keyboard application for Android or Windows Phone. For this, the application uses a Handover Select NDEF message (see BLE pairing message generation). However, you can easily modify the application to use only one LE OOB NDEF message (and support only Android) or only one EP OOB NDEF message (and support only Windows Phone). Also, you can configure the application to use Out-Of-Band pairing instead of Just Works pairing.

Note
This application is not power optimized!
This example uses a constant value for the Temporary Key for OOB pairing. To be compatible with the BLE Core Specification for OOB pairing, generate a random value for the Temporary key.
This application supports pairing with just one peer.

Setup

You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\ble_peripheral\experimental_ble_app_hids_keyboard_pairing_nfc

Button assignments: BSP BLE Button Assignments

Testing

Test the HID Keyboard Application with BLE pairing using NFC with a smartphone or tablet (with Android or Windows Phone, Android is recommended) that supports NFC by performing the following steps:

  1. Compile and program the application.
  2. Touch the NFC antenna with the smartphone or tablet and observe that the BSP_INDICATE_ADVERTISING state is indicated. LED 3 is lit when the NFC tag detects the NFC field (or, if Caps Lock is on, the LED blinks).
  3. Confirm pairing with 'Nordic_Keyboard' in a pop-up window on the smartphone/tablet and observe that the BSP_INDICATE_CONNECTED state is indicated.
  4. Test the HID Keyboard Application by using it as input keyboard for the system.

Documentation feedback | Developer Zone | Subscribe | Updated