apache / mynewt-nimble

Apache mynewt
https://mynewt.apache.org/
Apache License 2.0
710 stars 402 forks source link

Service Change Indication #1456

Open Koxx3 opened 1 year ago

Koxx3 commented 1 year ago

Hello,

I have troubles with Android phones and bonded ESP32 when adding/removing characteristics between 2 firmware releases (incorrect data reads, no answer on some characteristics ...) It seems a common issue, and I found a lot of users with the same troubles. I tried everything on the "client side" (Android cache refresh hack ... since it's not a public API), but it still doesn't work.

I found that BLE seems to already include "a flag" to indicate the client it needs to refresh his cache... the "Service Change Indication".

It doesn't seems NimBLEServer::serviceChanged() does the same thing (and it's not in the public API). https://github.com/h2zero/NimBLE-Arduino/blob/release/1.4/src/NimBLEServer.cpp#L168

Espressif seems to offer the API on bluedroid : https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/esp_gatts.html#_CPPv444esp_ble_gatts_send_service_change_indication13esp_gatt_if_t13esp_bd_addr_t

it seems related to the 0x2A05 characteristic

Could it be possible to offer an API for this in NimBLE please ?

More info here : https://stackoverflow.com/questions/62155016/bluez-and-service-characteristics-cache-issue-with-android

sjanc commented 1 year ago

Hi,

service/gatt package provides this functionality via ble_svc_gatt_changed() have a look at https://github.com/apache/mynewt-nimble/tree/master/nimble/host/services/gatt

If you implement GATT service on your own you may use ble_gatts_chr_updated() directly