4

The peripheral I'm connecting to has the Service Changed characteristic, and my understanding is that on connect, if the Service Changed characteristic is present, the client may not cache attributes if it is not bonded. There's a nice explainer on this here.

Now, I start with an empty /var/lib/bluetooth/[adapter] directory. If I use bluetoothctl to turn scan on, then off, I'll see my device. Then I connect to it, and discovery of services and characteristics happens (by monitoring the ATT messages using btmon). Great! Now I disconnect.

Examining the /var/lib/bluetooth/[adapter] directory shows:

  • directory /var/lib/bluetooth/[adapter]/[device]
  • file /var/lib/bluetooth/[adapter]/cache/[device]

Now, let me remove the device from bluetoothd:

bt-device -r [device]

Examining the /var/lib/bluetooth/[adapter] directory now shows:

  • file /var/lib/bluetooth/[adapter]/cache/[device]

That's troubling. And if I run bluetoothctl again, turn scan on, turn it off, and connect, I no longer see the characteristic discovery happen. Only service discovery. That does not obey the contract of the Service Changed characteristic.

If, instead, I manually delete /var/lib/bluetooth/[adapter]/cache/[device], then I see characteristic discovery.

Question:

Given that bt-device -r [device] does NOT remove the cache/[device] file, how do I programmatically remove that file without having to fire up a sudo rm process?

Robert B
  • 3,195
  • 2
  • 16
  • 13
  • 1
    do not use `sudo rm`, what happens if you use `RemoveDevice` from the `org.bluez.Adapter1` interface (try to remove the device in `bluetoothctl`). you can also try to disable cache in `/etc/bluetooth/main.conf` – Gal Ben-Haim Oct 31 '18 at 21:53

1 Answers1

0

I ran into this also.

From documentation for the python 'bleak' library, with bluez < 5.62, when reconnecting to a device whose configuration has changed, it appears as though one must manually delete the cache.

https://bleak.readthedocs.io/en/latest/troubleshooting.html

Otherwise BlueZ gives the cached values from the first time the device was connected.

bluetoothctl -- remove XX:XX:XX:XX:XX:XX

prior to BlueZ 5.62 you also need to manually delete the GATT cache

sudo rm "/var/lib/bluetooth/YY:YY:YY:YY:YY:YY/cache/XX:XX:XX:XX:XX:XX"

I confirmed this with BlueZ 5.55 - unless you delete the cache manually, BlueZ will not see the new downstream device configuration.