nRF51 SDK: Proximity Application for Eval Board

| nRF51 SDK

- Home
- Related Pages
- API Reference
- Data Structures

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Proximity Application for Eval Board

# Proximity Application for Evaluation Board

The Proximity Application is a firmware example that implements the Proximity profile using the Nordic nRF51822 evaluation board. The Proximity profile alerts the user when connected devices are too far apart.

The source code and project file can be found in the `<InstallFolder>\Nordic\nrf51822\Board\pca10001\s110\ble_app_proximity` folder.

The application includes all three services in the Proximity profile:

- Link Loss Service
- Immediate Alert Service
- TX Power Service

In addition, use of the Battery Service and Bonds and Persistent Data Manager are also demonstrated.

The Proximity Application does fast advertising for 30 seconds at power up and after a disconnection. It will then switch to slow advertising mode.

When an alert is signaled using by the central using the Immediate Alert Service, it is indicated as follows.

- If the alert level value is 2 (High Alert), then the Alert LED will be ON.
- If the alert level value is 1 (Mild Alert), then the Alert LED will blink.
- If the alert level value is 0 (No Alert), then the Alert LED will be OFF.

When an alert is signaled using by the central using the Link Loss Service, it is indicated as follows when there is a Link Loss.

- If the alert level value is 2 (High Alert), then the Alert LED will stay ON until reconnection happens.
- If the alert level value is 1 (Mild Alert), then the Alert LED will blink until reconnection happens.
- If the alert level value is 0 (No Alert), then the Alert LED will be OFF.

Battery measurement:

This application uses the ADC peripheral to measuare the battery level. It measures battery level every 2 minutes and sends the battery level as notification if there is a change in the battery level since previous measurement.

Note
  - The device will have to be in bonded state to change any characteristic in this application.
  - 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

    - 4 minutes, if advertising with whitelist was done.

      Push the button 0 restart advertising, or button 1 to erase all bonds and restart advertising.

Compiler Optimization:

This example is optimized for reduced power consumption. Therefore the default optimization level for this example application is 'Level 3', (`-O3`) and 'Optimize for Time', (`-Otime`). If the Keil debugger is needed for debugging purposes, then the optimization level should be changed to 'Level 0', (`-O0`) and 'Optimize for Time' should be removed in order to ease the use of the debugger.

# Setup

LED assignments:

- LED 0: Advertising LED
- LED 1: Alert LED

Buttons assignments:

- Button 0: Wake-up from system-off and restart advertising. In connected state, this button is used raise/clear High Alert to the central which has an Immediate Alert Service instance.
- Button 1: Wake-up from system-off erase all bonds and restart advertising. This button can be used to turn OFF the Alert LED (when it is blinking or ON due to an alert signalled by Central).

# Testing

The Proximity Application can be tested using the nRFUtility iOS Demo App (listed as "nRFready Utility" on App Store) on an iPhone 4s or the 'new iPad' (running on iOS version 5 or higher). The Find Me locater functionality of this application can be tested with an iPhone running iOS version 6 or higher. Note: When testing the nRFUtility app on iOS6, it must be noted that when touching the 'Disconnect' button the iOS device will not disconnect immediately. This issue is not seen on iOS5.

This application (except the Find Me locater functionality) can also be tested using nRF Utility app for Android (listed as "nRF Utility" in Google play).

The Proximity Application can also be tested using the Master Control Panel as follows:

1. Compile and program the application. Observe that the Advertising LED is blinking.
2. 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 Advertising LED is off.
3. In the Master Control Panel, 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 that the Alert LED is blinking. This indicates that the device is responding properly to the Mild Alert issued by the Central.
4. Press Button 1 and observe the LED stops blinking. This indicates the Alert clearing mechanism of this application is working properly.
5. Change the AlertLevel value to 2, and observe that the Alert LED is ON. This indicates that the device is responding properly to the High Alert issued by Central.
6. Change the AlertLevel value to 0, and observe that Alert LED is OFF. This indicates that the device is responding properly to the 'No Alert' issued by Central.
7. In the Master Control Panel, Set the value of AlertLevel characteristic in Link Loss Service to 1 (Mild Alert).
8. Simulate a link loss situation (e.g. by shielding the devices), and observe that the Alert LED and the Advertising LED are blinking. This indicates that the device had properly received the 'Mild Alert' issued by the Central and is now indicating a Link Loss and also advertising.
9. Reconnect and observe that both LEDs are OFF.
10. In the Master Control Panel, Set the value of AlertLevel characteristic in Link Loss Service to 2 (High Alert).
11. Simulate a link loss situation (e.g. by shielding the devices), and observe that the Alert LED is ON and the Advertising LED is blinking. This indicates that the device had properly received the 'High Alert' issued by the Central and is now indicating a Link Loss and also advertising.
12. Reconnect and observe that both LEDs are OFF.
13. Select the TxPowerLevel characteristic in TX Power Service, click the 'Read' button and verify that it was successfully read.
14. Click the 'Enable services' button to start notification of Battery Level and observe that one Battery level value is received (seen as HandleValueNotification on the Master Control Panel log) after 2 minutes.
15. Disconnect from the Master Control Panel and observe that the only Advertising LED is blinking.
16. Wait until the application goes to system-off (Advertising LED turns OFF).
17. Press button 0 and connect from the Master Control Panel by pressing the 'Connect' Button. Observe that Advertising LED is OFF.
18. In the Master Control Panel, set the AlertLevel characteristic in Immediate Alert Service to 2, and observe that the Alert LED is ON. This indicates that the device has used previous bonding information to recognize the Central and has also started accepting commands from it.
19. Disconnect from the Master Control Panel and allow the device to go to System Off mode (happens after 3 minutes).
20. Press button 1 (erase bonds) and connect from the Master Control Panel by pressing the 'Connect' button. Observe that the link encryption is OFF.
21. In the Master Control Panel, Set the AlertLevel characteristic in Immediate Alert Service to 1, and observe that the Alert LED is NOT blinking. This indicates that the device has NOT recognized the central because the bonding information was erased from the device.
22. Disconnect from Master Control Panel.

Testing Find Me locater (Immediate Alert Service Client) functionality:

1. In the Master Control Panel create the Immediate Alert Service (IAS) server by doing the following steps:
   - Click File -> Server Setup. In the window that opened up, click File -> Load setup.
   - In the resulting window, navigate to ble_app_proximity folder and load the file named findMeMasterServer.bin.
   - Click 'Stop Server' button and then 'Start Server'. This would restart the server with Immediate Alert Service configured.
   - It is important to keep the 'Server Setup' window opened.
2. Go to the Master Control Panel main window, and connect to the device.
3. Press Button 0 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.
4. Press Button 0 again and observe that the AlertLevel value changes to 00. This indicates that the device was able to clear the High Alert previously signaled to the central.