- 
                Notifications
    You must be signed in to change notification settings 
- Fork 330
Description
- bleak version: 0.12.1
- Python version: 3.8
- Operating System: Ubuntu 20.04
- BlueZ version (bluetoothctl -v) in case of Linux: git commit 43e95ba70 (>5.60, <5.61)
Description
We have custom firmware for a BLE device. After adding a PnP ID characteristic to the Device information service (thus causing all attributes after that to be renumbered), Bleak started giving bleak.exc.BleakError: This descriptor is already present in this BleakGATTServiceCollection! when connecting to the device.
This is the same error as #376 but a different cause.
What I Did
- Flash firmware v3.0.x from https://code.pybricks.com
- Connect to the device with BlueZ
- Flash firmware v3.1.x from https://beta.pybricks.com
- Connect to the device with BlueZ/Bleak
Additional info
There appears to be a bug in BlueZ since it affects WebBluetooth in the Chromium browser as well as Bleak. We discussed this in pybricks/support#374.
In Bleak, we already have known for a while that when you have a custom BLE device like this and you add/move/rearrange the attributes reported by the device, you need to remove the device from BlueZ with bluetoothctl remove XX:XX:XX:XX:XX:XX. However, it appears that this is not always enough.
Here is a log from bluetoothctl when the BleakError occurs:
[CHG] Controller 00:1A:7D:DA:71:0C Discovering: no
[CHG] Device 90:84:2B:00:A8:8D Connected: yes
[DEL] Characteristic (Handle 0xd097)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009/char000a
	00002a26-0000-1000-8000-00805f9b34fb
	Firmware Revision String
[DEL] Characteristic (Handle 0xd097)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009/char000c
	00002a28-0000-1000-8000-00805f9b34fb
	Software Revision String
[DEL] Primary Service (Handle 0x0073)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009
	0000180a-0000-1000-8000-00805f9b34fb
	Device Information
[DEL] Descriptor (Handle 0x0006)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service000e/char000f/desc0011
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[DEL] Characteristic (Handle 0xd097)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service000e/char000f
	c5f50002-8280-46da-89f4-6d8051e4aeef
	Vendor specific
[DEL] Primary Service (Handle 0x0073)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service000e
	c5f50001-8280-46da-89f4-6d8051e4aeef
	Vendor specific
[DEL] Characteristic (Handle 0xd097)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0012/char0013
	6e400002-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART TX
[DEL] Descriptor (Handle 0x0006)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0012/char0015/desc0017
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[DEL] Characteristic (Handle 0xd097)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0012/char0015
	6e400003-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART RX
[DEL] Primary Service (Handle 0x0073)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0012
	6e400001-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART Service
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[NEW] Secondary Service (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009
	0000180a-0000-1000-8000-00805f9b34fb
	Device Information
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009/char000a
	00002a26-0000-1000-8000-00805f9b34fb
	Firmware Revision String
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009/char000c
	00002a28-0000-1000-8000-00805f9b34fb
	Software Revision String
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0009/char000e
	00002a50-0000-1000-8000-00805f9b34fb
	PnP ID
[NEW] Secondary Service (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0010
	c5f50001-8280-46da-89f4-6d8051e4aeef
	Vendor specific
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0010/char0011
	c5f50002-8280-46da-89f4-6d8051e4aeef
	Vendor specific
[NEW] Descriptor (Handle 0x6fc4)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0010/char0011/desc0013
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[NEW] Primary Service (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0014
	6e400001-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART Service
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0014/char0015
	6e400002-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART TX
[NEW] Characteristic (Handle 0x8461)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0014/char0017
	6e400003-b5a3-f393-e0a9-e50e24dcca9e
	Nordic UART RX
[NEW] Descriptor (Handle 0xf9c4)
	/org/bluez/hci0/dev_90_84_2B_00_A8_8D/service0014/char0017/desc0019
	00002902-0000-1000-8000-00805f9b34fb
	Client Characteristic Configuration
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device 90:84:2B:00:A8:8D UUIDs: 6e400001-b5a3-f393-e0a9-e50e24dcca9e
[CHG] Device 90:84:2B:00:A8:8D UUIDs: c5f50001-8280-46da-89f4-6d8051e4aeef
[CHG] Device 90:84:2B:00:A8:8D ServicesResolved: yes
[CHG] Device 90:84:2B:00:A8:8D Modalias: bluetooth:v0397p0041d0000
[CHG] Device 90:84:2B:00:A8:8D ServicesResolved: no
[CHG] Device 90:84:2B:00:A8:8D Connected: no
We can see that the services/characteristics/descriptors are removed and added back again after the device has connected. And following up on what I asked in #376 (comment), we can see that the services are removed and added back in before ServicesResolved: yes (which is contrary to my previous suppositions).
Bleak currently doesn't handle the InterfacesRemoved D-Bus signal in client.py which leads to this error. There is a proposal to fix this in #625.