Integrating ANCS into BLE Application: Challenges and Solutions

Hi everyone, I’m currently working on integrating the Apple Notification Center Service (ANCS) into an existing BLE application using the nRF5 SDK 17.1.0. I’ve successfully set up the basic structure, but I’m encountering an issue where the device disconnects immediately after establishing a connection, specifically triggering the BLE_GAP_EVT_PHY_UPDATE_REQUEST event. This is quite puzzling, and I’m seeking some guidance on how to resolve this.

First, I want to share a bit about my setup. I’m using a custom board, so I haven’t incorporated the BSP library. The application is based on the ble_app_uart example, which I’ve modified to include ANCS functionality. The code compiles without issues, and the device does connect initially, but the subsequent disconnection is unexpected.

I’ve reviewed the connection parameters and event handling, but I’m not seeing any immediate red flags. The logs indicate that the connection is established with an error code of 0, which suggests everything is fine at that point. However, the PHY update request event follows shortly after, leading to the disconnection.

I’m wondering if there are specific configurations or code adjustments required to handle this event properly. Perhaps there’s a missing step in the event handling that’s causing the disconnection. I’ve also considered whether the PHY update request is being processed correctly, but I’m not entirely sure how to verify that.

Additionally, I’m curious if others have encountered similar issues when integrating ANCS into their applications. Have there been any common pitfalls or best practices that I should be aware of? Any insights or suggestions would be greatly appreciated!

For reference, here are some snippets from my code and logs:

Code Snippet (Event Handler):
c
void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
uint32_t err_code;
pm_handler_secure_on_connection(p_ble_evt);
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
printf(“Connected \n”);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
printf(“Connected err_code = %d \n”, err_code);
APP_ERROR_CHECK(err_code);
break;

    case BLE_GAP_EVT_DISCONNECTED:
        printf("Disconnected \n");
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        if (p_ble_evt->evt.gap_evt.conn_handle == m_ancs_c.conn_handle)
        {
            m_ancs_c.conn_handle = BLE_CONN_HANDLE_INVALID;
        }
        break;

    case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            printf("PHY update request.\n");
            ble_gap_phys_t const phys = { .rx_phys = BLE_GAP_PHY_AUTO, .tx_phys = BLE_GAP_PHY_AUTO, };
            err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
            APP_ERROR_CHECK(err_code);
        }
        break;

    // Other event handlers...
}

}

**Logs:**Fast advertising
ble_app_init
Connected
Connected err_code = 0
PHY update request.

I’m hoping someone with experience in ANCS integration or BLE connection management can shed some light on this issue. Any advice or pointers would be invaluable as I work through this challenge.

Thanks in advance for your help!