ThomasGerstenberg/blatann

Feature request: cache peer remote database

Opened this issue · 2 comments

Hi, I found this library when trying to integrate https://github.com/NordicSemiconductor/pc-ble-driver-py in a project using a Fanstel USB840F dongle with connectivity firmware, and it saves me a lot of time. Very good job, thankyou very much.

It would be nice to include a procedure for caching peers' remote databases, so it is not necesary to discover services when they are connected, if they were previously known. That would speed up the connection procedure. Maybe a json serialization of the database based on the device name

This is a feature I've had in the backlog for awhile but haven't had (or taken) the time to implement. I'll see if I have time to start fleshing it out in the next week or so

I'm thinking that the cache should be managed by the consumer (not blatann) and in a format such that the user could even hand-create the database definition to use and supply upon connection. Likely some sort of routine like peer.database.get_specs() which returns an easily serializable data structure. The consumer can then serialize and save however they want (json seems like the obvious choice). Then it can be deserialized back into the data structure and use something like peer.database.load_from_specs()

Probably would want to extend this to the server-side so users can define their GATT database in json or whatever and configure the device that way instead of programmatically

Yes, I agree it would be even better moving the cache control to the user, so it would be possible to pre-populate the services database and giving a fine control over them.

I used that approach for a driver for cypress dongle with EZ Serial firmware (https://www.cypress.com/documentation/software-and-drivers/ez-serial-ez-ble-module-firmware-platform), and build a json-based cache using the device name (this was the case that better fits my needs), so I only need to read the services the first time a device is connected, and when connecting with a device with the same name (no matter it can be a different device), I populate the services from the json.

I tried to do a similar thing with blatann, caching the peer.database.services when first connecting the device, and replacing the peer.database._services when reconecting the device with the cached one (plus recursively replacing peer and ble_driver in the services/characteristcs/attributes with those from current device and the attribute._manager with peer.database._read_write_manager), but no success, so I give up...