Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save service discovery during bonding makes it impossible to get data from some bonded devices on reconnect #903

Open
brianreinhold opened this issue Jul 22, 2024 · 3 comments

Comments

@brianreinhold
Copy link

A BLE peripheral that bonds also assumes that the services and characteristics and descriptors discovered during the bonding connection are saved by the client such that on a reconnect, after encryption, service discovery is unnecessary and the peripheral can notify and/or indicate it's data. There are several health devices that do this.

With the aioble library, one is forced to do service discovery every connection in order to subscribe to notifications/indications. However, service discovery is painfully slow, and long before it is done the health device has already indicated/notified its data and by the time one has subscribed (if the device does not disconnect) the data has already been evented and nothing is received.

How to work around this?

Is this a possible work-a-round?

Edit the code so that the start, end, and value handles are made public instead of private
Save these handles and UUID for each service, characteristic, and descriptor discovered
Recreate the ClientService, ClientCharacteristic, and ClientDescriptor for each of the saved items (of interest)
Change the subscribe method such that it uses the saved ClientDescriptor instead of doing further discovery operations to get the Descriptor.

I do not know if that is possible as the devil is always in the details. But to those who are familiar with the inner workings of aioble, is this something one could do, or is it far more complicated that that?

@andrewleech
Copy link
Contributor

Ah, yeah that's a tricky issue. I haven't had to deal with a device that assumes everything is cached and sends notifications / events immediately after connection like that!

I'm thinking there will be more needed at the C level to support this, in particular the exposing CCCD for caching will certainly be needed to maintain the subscriptions to characteristics. I started work on that a few years ago but didn't have the resources to finalise and test it.

Oh wait, CCCD is more about the device / server end isn't it, you're referring more to the client / central side wanting to cache the characteristics. I'm really not as familar with that side, I've only developed devices myself.

I'm not sure if the central side stack needs to be informed about the characterisics to set up buffers or anything? Maybe if it's just characteristic identifiers then exposing them to be saved / resored in the json file would be enough; certainly that makes sense to start with to see if it works?

@brianreinhold
Copy link
Author

brianreinhold commented Jul 23, 2024 via email

@brianreinhold
Copy link
Author

brianreinhold commented Jul 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants