nRF5 SDK v15.0.0
Proximity Application
This example requires one of the following SoftDevices: S112, S132, S140

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

The Proximity Application is an example that implements the Proximity Profile and the Find Me Profile using the hardware delivered in the nRF5 Development Kit. The Proximity Profile alerts the user when connected devices are too far apart, while the Find Me Profile is used to alert the remote device (for example, a phone).

The application includes the following services:

In addition, use of the Battery Service is also demonstrated.

At each power up and disconnect, the Proximity Application will do 3 minutes of fast advertising without whitelist, which is indicated by the BSP_INDICATE_ADVERTISING state. It will then switch to sleep mode, and the state BSP_INDICATE_IDLE is indicated. When the link is lost, or when an alert is signaled using the Immediate Alert Service, an alert is indicated using the state BSP_INDICATE_ALERT_0 or BSP_INDICATE_ALERT_1, depending on the value of the Alert Level characteristic.

The example uses the ADC peripheral to measure the battery level every 2 minutes. If there is a change in the battery level, the application sends the current level as notification.

Note
This application is not power optimized!
  • The device must be in bonded state to change any characteristic in this application.
  • The TX Power Level characteristic is not writable.
  • The application will stop advertising and go to system-off mode after 3 minutes and 30 seconds (if no advertising with whitelist was done) or after 4 minutes (if advertising with whitelist was done). Push Button 1 to restart advertising, or push and hold Button 1 for 5 seconds to erase all bonds and restart advertising.
  • Upon disconnecting a bonded connection, the application will advertise with whitelist for ADV_INTERVAL_FAST_PERIOD seconds. After this time-out, the application will be able to bond to a new central.

Setup

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

Button assignments - in addition to those defined in BSP BLE Button Assignments:

Testing

Test the Proximity Application with the nRF Toolbox app, which is available on both iOS (App Store) and Android (Google Play).

You can also test the application with nRF Connect by performing the following steps:

  1. Compile and program the application. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
  2. Connect to the device from nRF Connect (the device is advertising as 'Nordic_Prox'), then bond to the device. To bond, click the settings button for the device in nRF Connect, select "Pair", check "Perform Bonding", and click "Pair". Wait until the bond is established before you continue. Observe that the BSP_INDICATE_CONNECTED state is indicated.
  3. Set the AlertLevel characteristic in Immediate Alert Service to 1 (enter '01' in the text box, and click the 'write' button), and observe the Mild alert (BSP_INDICATE_ALERT_0).
  4. Change the AlertLevel value to 2 and observe the High alert (BSP_INDICATE_ALERT_3).
  5. Change the AlertLevel value to 0 and observe BSP_INDICATE_ALERT_OFF.
  6. Set the AlertLevel characteristic in Link Loss Service to 1.
  7. Simulate a link loss situation, for example by shielding the board, and observe that both BSP_INDICATE_ALERT_0 and BSP_INDICATE_ADVERTISING are indicated.
  8. Reconnect and observe that only the BSP_INDICATE_CONNECTED state is indicated.
  9. Set the AlertLevel characteristic in Link Loss Service to 2.
  10. Simulate a link loss situation, for example by shielding the board, and observe that the BSP_INDICATE_ALERT_3 and BSP_INDICATE_ADVERTISING are indicated.
  11. Reconnect and observe that only the BSP_INDICATE_CONNECTED state is indicated.
  12. Select the TxPowerLevel characteristic in TX Power Service, click the 'read' button, and verify that it was successfully read.
  13. To start notification of Battery Level click the 'Play' button in the Battery Service and observe that the battery level is notified periodically (if there is a change).
  14. Disconnect the device in nRF Connect and observe that BSP_INDICATE_ADVERTISING is indicated.
  15. Wait until the application goes to system-off (BSP_INDICATE_IDLE).
  16. Press Button 1 and reconnect to nRF Connect. Observe that BSP_INDICATE_CONNECTED is indicated and that the battery level is notified periodically (if there is a change).
  17. Disconnect the device in nRF Connect.
  18. Connect with a different nRF Connect central and bond and disconnect.
  19. Wait until the application goes to system-off (BSP_INDICATE_IDLE).
  20. Press Button 1 and reconnect to the first nRF Connect central. Observe that BSP_INDICATE_CONNECTED is indicated and that the battery level is notified periodically (if there is a change).
  21. Disconnect the device in nRF Connect.
  22. Connect with the second central and observe that the link encryption is on and that the battery level is not notified.
  23. Disconnect from the second central and wait for the application to go to system-off.
  24. Press and hold Button 2 (erase bonds) for 5 seconds and connect with the first nRF Connect. Observe that the link encryption is OFF ("Security updated, mode:1, level:1") and that no notifications are received.
  25. Disconnect from nRF Connect.

Test the Find Me locater (Immediate Alert Service Client) functionality by performing the following steps:

  1. In nRF Connect, create the Immediate Alert Service (IAS) server by performing the following steps:
    • In Server Setup, click the settings button and select "Load setup".
    • In the resulting window, navigate to the <InstallFolder>\examples\ble_peripheral\ble_app_proximity folder. Load the file findMeMasterServer.ncs.
    • Click "Apply to device" and navigate back to Connection Map.
  2. Connect to the device.
  3. Press Button 1 and observe that the AlertLevel value at the server in nRF Connect changes to 02. This indicates that the device was able to signal a High Alert to the central.
  4. Press Button 1 again and observe that the AlertLevel value changes to 00. This indicates that the device was able to clear the High Alert previously signalled to the central.

Documentation feedback | Developer Zone | Subscribe | Updated