This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Issue getting iPhone to do a full service discovery using sd_ble_gatts_service_changed()

nRF SDK Version 16.0.0
nRF52840
iOS version 15.2

I'm having an issue with my iPhone displaying incorrect characteristic data after doing a DFU to my nRF device, re-connecting, and reading the DIS service characteristics.  I understand the iPhone having a caching issue, particularly when a change is made to a service or a new service is added but this is not the case.  And of course when I reboot my iPhone, the data is read and displayed properly.  We tried the trick of changing the BLE address after the device boots back up and this does fix the issue but consider this a 'hack' and not an optimal solution to this issue.  I've read through similar posts on DevZone regarding this same problem but have found nothing that has solved my issue.

We are not using bonding and I dont initialize the Peer Manager in my project.  Is Peer Manager necessary for sd_ble_gatts_service_changed() to work properly?

I did notice early on that my NRF_SDH_BLE_SERVICE_CHANGED setting in sdk_config.h was set to 0 but I now have it set to 1 in the new image that we are sending over DFU.  Note that the pre-DFU image on the device was built with this setting set to 0.  Not sure if this matters or not.

I found that I'm always getting an error when calling sd_ble_gatts_service_changed(conn_handle, 0x00, 0xFFFF) no matter what I pass in for the handles.  I've tried a starting handle of 0 and 0x0C which is supposedly greater than the service changed cccd handle but seem to always get a return code of 0x3003 (BLE_ERROR_INVALID_ATTR_HANDLE).  Ive tried callling sd_ble_gatts_service_changed in the Connection Event when the phone first connects and even later in the NRF_BLE_GATT_EVT_ATT_MTU_UPDATED event but always the same error code.


So the big questions are, how do I get my iPhone to do a full service discovery everytime it connects to my device?  What is the proper way to use sd_ble_gatts_service_changed() so that it works and returns SUCCESS?

Thanks for the help

Parents
  • Hello,

    I am afraid there are not any elegant workarounds for this. You have to force clearing of the cache on the iPhone in order for it to discover that the service changed characteristic has been added to your updated application. The known ways to clear the cache is to do a reboot of phone, toggle flight mode enable, or by changing the address like you mentioned. I wish there were other ways to force a new service discovery on iOS..

    The iPhone will not do caching once it has discovered that the service changed characteristic is present. This means it will perform a full service discovery on all subsequent connections.

    Sending of service indication is used for bonded devices. It requires that the client is subscribed to the indication.

    Best regards,

    Vidar

Reply
  • Hello,

    I am afraid there are not any elegant workarounds for this. You have to force clearing of the cache on the iPhone in order for it to discover that the service changed characteristic has been added to your updated application. The known ways to clear the cache is to do a reboot of phone, toggle flight mode enable, or by changing the address like you mentioned. I wish there were other ways to force a new service discovery on iOS..

    The iPhone will not do caching once it has discovered that the service changed characteristic is present. This means it will perform a full service discovery on all subsequent connections.

    Sending of service indication is used for bonded devices. It requires that the client is subscribed to the indication.

    Best regards,

    Vidar

Children
No Data
Related