ukBaz / python-bluezero

A simple Python interface to Bluez
MIT License
396 stars 112 forks source link

Enable services changed on Generic Attribute service #405

Open chadrockey opened 10 months ago

chadrockey commented 10 months ago

My iOS development device is constantly caching the gatt services and characteristics and won't forget them for 24 to 48 hours. Even with a restart and bluetooth off/on, it's so sticky and really slows development sometimes.

Is there a way to advertise the services changed characteristic on the Generic Attribute service?

The Generic Attribute service is 0x1801 (00001801-0000-1000-8000-00805F9B34FB), but when I try to register this service, I get the following:

bluezero.GATT - WARNING - Failed to register application: org.bluez.Error.Failed: Failed to create entry in database

The Services Changed characteristic is 0x2A05 and is a notify characteristic.

If we find a way to do this, I'll make a PR so that it can be a quick toggle from high level code such as:

my_peripheral.enable_services_changed()

ukBaz commented 10 months ago

It is a while since I've looked in to the details of this, but I seem to remember that it was not very straight forward as the BlueZ daemon wanted to handle some of this. There are also other characteristics like 0x2B2A which is the Database Hash characteristic.

I've not done much with iOS, but I have seen the problem of devices being cached. Deleting devices will normally remove them from the cache. Restarting the Bluetooth daemon is also something I did frequently to ensure a clean environment during development.

If you do want to pursue getting this working then you will need to look for more detail on what is failing. For example, starting the bluetoothd in debug mode. Or at the output from btmon. I suspect this is a question for the BlueZ Slack. Once it is known how to do it with the BlueZ API, we can then look at how to make it work with the abstraction that Bluezero tries to put in place.