This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 SDK16 Service Discovery doesn't happen on iOS

Hi, I'm having some issues with migrating from SDK12.1 to SDK16 while discovering services.

It seems to connect to Android without much issue, but on iOS the connection fails. From running testing connecting from a linux with a BLE connection through node js it looks like the services are not discovered. I don't see any information about how to enable service discovery on connection or how to migrate from 12.1 to 16.0.0 on the forums, in the examples or in the documentation.

Does anyone have any suggestions?

Parents
  • Hi,

    It sounds like this is caused by attribute caching. iOS may remember the services across connections so it don't have to repeat service discovery on every re-connect, which may become a problem if you re-program the device with new FW. Please try to clear the cache by forgetting the device in bluetooth settings (if bonded) followed by toggling the flight mode. The phone should then perform a new service discovery next time you connect.

  • Unfortunately, I've never had it successfully connect to this device on iOS. It just tries, never discovers the services and gives up. For completeness sake I did check for any previous bonding on the phone and try toggling airplane mode. Thanks for the suggestions. Unfortunately, no change.

  • I assumed the old attributes were displayed at first. Now I suspect the issue may be that the app is not responding to a Softdevice event like it should. This can cause the service discovery to hang, and eventually time out. Does your app call gatt_init() on startup like the other SDK BLE examples? This enables the GATT Module which will respond to any MTU and Data length update requests from the central.  

  • I have a handler for the gatts events, but it doesn't seem to ever get called while connecting to the nordic. Even when I connect via Android, it works, but it does not interact with the gatts event handler at all. I suspect this may be my issue, but I don't know how to resolve it.

  • So just to confirm, is the nrf_ble_gatt_init() function being called on startup in your app? Whether you will actually receive a MTU requests depends on your setup and the peer device you are connected to. Another thing you may want to check is if the BLE_GATTS_EVT_SYS_ATTR_MISSING event is handled. It's usually handled by the Peer manager module, but I'm not sure if you project includes it. If not, you need to make sure you're implementing the same handling as in the ble_app_uart example.

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
        ..
            case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            // No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;
            ...

  • I discovered the issue it was due to not handling the BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST case properly. It was not responding with an accurate MTU_SIZE.

            case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
                printf("Exchange MTU Request\n");
                err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle,
                                                           NRF_BLE_MAX_MTU_SIZE);
                APP_ERROR_CHECK(err_code);
                break; // BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST

Reply
  • I discovered the issue it was due to not handling the BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST case properly. It was not responding with an accurate MTU_SIZE.

            case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
                printf("Exchange MTU Request\n");
                err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle,
                                                           NRF_BLE_MAX_MTU_SIZE);
                APP_ERROR_CHECK(err_code);
                break; // BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST

Children
No Data
Related