BLEAncs

The Bluefruit nRF52 BSP codebase is undergoing active development based on customer feedback and testing. As such, the class documentation here is incomplete, and you should consult the Github repo for the latest code and API developments: https://goo.gl/LdEx62

BLEAncs is a helper class that enables you to receive notifications from the Apple Notification Center Service from devices such as an iPhone or iPad. It can be used to receive alerts such as incoming or missed calls, email messages, or most alerts that appear on the mobile device's screen when locked.

API

Because the BLEAncs class is a work in progress, the latest public API for the BLEAncs helper class should be viewed here.

ANCS OLED Example

The ancs_oled example uses the Adafruit FeatherWing OLED to display any incoming alerts.

Sketch Requirements

In order to use this example sketch the following libraries must be installed on your system:

Loading the Sketch

The ancs_oled sketch can be loaded via the examples menu under Peripheral > ancs_oled:

With the sketch loaded, you can build the firmware and then flash it to your device via the Upload button or menu option:

Make sure that the Adafruit_SSD1306.h file has the 'SSD1306_128_32' macro enabled. Running the sketch with 'SSD1306_128_64' set will cause corrupted data to appear on the OLED display.

Once the sketch is running on the nRF52 Feather you can proceed with the one-time pairing process, described below.

Pairing to your Mobile Device

Before you can start receiving notifications, you will need to 'pair' the nRF52 Feather and the mobile device.

The pairing process causes a set of keys to be exchanged and stored on the two devices so that each side knows it is talking to the same device it originally bonded with, and preventing any devices in the middle from eavesdropping on potentially sensitive data.

The one-time pairing process is described below, and assumes you are already running the ancs_oled sketch on your nRF52 device.

1. In the Settings app go to Bluetooth:

2. Scroll to the bottom of the list of 'My Devices' and click on Bluefruit52 under Other Devices:

3. When the pairing dialog box comes up, click the Pair button:

4. Wait for the pairing process to complete, at which point Bluefruit52 should appear in the My Devices list with the Connected status:

Once two devices have been paired, they will automatically reconnect to each other whenever they are in range and have their Bluetooth radios enabled.

Wait for Alerts

At this point, any alerts that the mobile device generates will be displayed on the OLED display along with the notification category and date:

Certain alerts (such as incoming calls) can also have actions associated with them, making use of the three buttons on the left-hand side of the display to decide which action to take.

In the ancs_oled example, we have a special section of code for incoming calls where you can accept or decline a call with an appropriate button press:

Download: file
  // Check buttons
  uint32_t presedButtons = readPressedButtons();

  if ( myNotifs[activeIndex].ntf.categoryID == ANCS_CAT_INCOMING_CALL )
  {
    /* Incoming call event
     * - Button A to accept call
     * - Button C to decline call
     */
    if ( presedButtons & bit(BUTTON_A) )
    {
      bleancs.actPositive(myNotifs[activeIndex].ntf.uid);
    }

    if ( presedButtons & bit(BUTTON_C) )
    {
      bleancs.actNegative(myNotifs[activeIndex].ntf.uid);
    }
  }
This guide was first published on Mar 22, 2017. It was last updated on Mar 22, 2017. This page (BLEAncs) was last updated on Jul 16, 2019.