-
Hi, I've been struggling with this, and trying a few workarounds, but I feel this might be something that is hopefully user error... I'm trying to implement OTA flashing for silabs efr32 devices, which basically involves writing to a characteristic to trigger a reboot into a bootloader, and eventually, writing to the same charactistic uuid to reboot back into the application. The handles change, and the device disconnects and must be reconnected to. I've tried making a new client for the second stage (as suggested in #121) , and I've tried using a single client, and calling .connect(), but it never works reliably. I've tried the workaround from #713 (comment) and have used workarounds to select the correct handle, instead of using the UUID, but it never reliably reboots both times. I can normally connect, request the first reboot, and then connect again, but the request to write to the characteristic after reboot invariably fails. I've got demo code and logs available at https://github.com/karlp/bleak-demo-ota The demo code attempts to use a single client object. I've tried the approaches in #549 and read far too many bug reports and discussions to link them all relevantly. Any advice greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
The device itself must implement the GATT Database Hash characteristic or the Service Changed characteristic in order for BlueZ to correctly re-enumerate the device. There is some discussion of this at bluez/bluez#191. Also, Bleak does not handle service change events, so you need to create a new |
Beta Was this translation helpful? Give feedback.
-
I got this "working" in the end by editing /etc/bluetooth/main.conf and setting With the default, even though I have a new client, somehow the BleakGATTServiceCollection remains the same, or, more correctly I guess, is refilled by the cached values from blueZ, giving me the errors like so
I would like to believe that this is "fixable" though, so I tried using what bluezero does, where they "remove" devices to keep getting beacons, see: https://github.com/ukBaz/python-bluezero/blob/main/bluezero/observer.py#L64 and https://github.com/ukBaz/python-bluezero/blob/main/bluezero/adapter.py#L260 I tried adding this into the bluezdbus/client.py: _cleanup_all(), but it didn't work. I suspect I'm just "doing it wrong" though, it certainly seems like removing the device like this should absolutely get rid of it's cached services/characteristics.
I can work with just changing my bluetooth/main.conf, but this feels very close to being able to work out of the box, so I'm sharing this in the hopes that someone else who knows this stuff more can push this further, if I'm on the right track. |
Beta Was this translation helpful? Give feedback.
I got this "working" in the end by editing /etc/bluetooth/main.conf and setting
Cache=yes
instead of the defaultCache=always
With the default, even though I have a new client, somehow the BleakGATTServiceCollection remains the same, or, more correctly I guess, is refilled by the cached values from blueZ, giving me the errors like so