The Proximity Application is an example that implements the Proximity profile using the hardware delivered in the nRF51 Development Kit. The Proximity profile alerts the user when connected devices are too far apart.
The application includes all three services in the Proximity profile:
In addition, use of the Battery Service and Device Manager are also demonstrated.
At each power up and disconnect, the Proximity Application will do 20 seconds of fast advertising with whitelist followed by 40 seconds of fast advertising without whitelist. It will then switch to slow advertising mode, and the state BSP_INDICATE_ADVERTISING_WHITELIST 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.
- 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
The name of the example is ble_app_proximity_s110_pca10028. If you are not using the Keil Pack Installer, you can find the source code and project file of the example in the following folder: <InstallFolder>\Nordic\nrf51\examples\ble_peripheral\ble_app_proximity
There is also a power-optimized version of this example. The name of the example is ble_app_proximity_low_power_s110_pca10028. If you are not using the Keil Pack Installer, you can find the source code and project file of the example in the following folder: <InstallFolder>\Nordic\nrf51\examples\ble_peripheral\ble_app_proximity_low_power
Button assignments:
- Button 1: Wake up from system-off and restart advertising. In connected state, this button is used to raise/clear High Alert to the central, which has an Immediate Alert Service instance.
- Button 2: Hold for 5 seconds to wake up from system-off, erase all bonds, and restart advertising.
Testing
Test the Proximity Application with the nRF Toolbox app, which is available on both iOS (Apple Store) and Android (Google Play).
You can also test the application with the Master Control Panel by performing the following steps:
- Compile and program the application. Observe that the BSP_INDICATE_ADVERTISING state is indicated.
- Connect to the device from Master Control Panel (the device will be advertising as 'Nordic_Prox'), then bond and perform service discovery. Observe that the BSP_INDICATE_CONNECTED state is indicated.
- Set the AlertLevel characteristic in Immediate Alert Service to 1 (click the 'hex' radio button, enter '01' in the text box, and click the 'Send update' button), and observe the Mild alert (BSP_INDICATE_ALERT_0).
- Change the AlertLevel value to 2 and observe the High alert (BSP_INDICATE_ALERT_3).
- Change the AlertLevel value to 0 and observe BSP_INDICATE_ALERT_OFF.
- Set the AlertLevel characteristic in Link Loss Service to 1.
- Simulate a link loss situation (for example by shielding the Master Emulator) and observe that both BSP_INDICATE_ALERT_0 and BSP_INDICATE_ADVERTISING are indicated.
- Reconnect and observe that only the BSP_INDICATE_CONNECTED state is indicated.
- Set the AlertLevel characteristic in Link Loss Service to 2.
- Simulate a link loss situation, for example by disconnecting the Master Emulator, and observe that the BSP_INDICATE_ALERT_3 and BSP_INDICATE_ADVERTISING are indicated.
- Reconnect and observe that only the BSP_INDICATE_CONNECTED state is indicated.
- Select the TxPowerLevel characteristic in TX Power Service, click the 'Read' button, and verify that it was successfully read.
- Click the 'Enable services' button to start notification of Battery Level and observe that the battery level is notified periodically.
- Disconnect from the Master Control Panel and observe that BSP_INDICATE_ADVERTISING is indicated.
- Wait until the application goes to system-off (BSP_INDICATE_IDLE).
- Press button 1 and connect to the Master Control Panel. Observe that BSP_INDICATE_CONNECTED is indicated and that the battery level is notified periodically.
- Disconnect from the Master Control Panel.
- Connect with a different central and bond and disconnect.
- Wait until the application goes to system-off (BSP_INDICATE_IDLE).
- Press button 1 and reconnect to the first Master Control Panel. Observe that BSP_INDICATE_CONNECTED is indicated and that the battery level is notified periodically.
- Disconnect from the Master Control Panel.
- Connect with the second central and observe that the link encryption is on and that the battery level is not notified.
- Disconnect from the second central and wait for the application to go to system-off.
- Press and hold button 2 (erase bonds) for 5 seconds and connect with the first Master Control Panel. Observe that the link encryption is OFF and that no notifications are received.
- Disconnect from Master Control Panel.
Test the Find Me locater (Immediate Alert Service Client) functionality by performing the following steps:
- In the Master Control Panel, create the Immediate Alert Service (IAS) server by performing the following steps:
- Click File -> Server Setup. In the window that is displayed, click File -> Load setup.
- In the resulting window, navigate to ble_app_proximity folder and load the file named findMeMasterServer.bin.
- Click the 'Stop Server' button and then 'Start Server'. This restarts the server with Immediate Alert Service configured.
- You must keep the 'Server Setup' window opened.
- Go to the Master Control Panel main window and connect to the device.
- Press button 1 and observe that the AlertLevel value at the 'Server setup' window of the Master Control Panel changes to 02. This indicates that the device was able to signal a High Alert to the central.
- 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.