-
Notifications
You must be signed in to change notification settings - Fork 304
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
Windows : Failed to connect to device: Could not get GATT characteristics #1291
Comments
GATT-Wider.zip |
The program is not complete, so it is impossible to say what could be happening. Please provide a full minimal reproducible test case. |
Hello here is a fully reproducible test . import asyncio
from bleak import BleakClient
async def discover_services_and_handles(device_address):
async with BleakClient(device_address) as client:
services = await client.get_services()
for service in services:
print(f"Service: {service.uuid}")
for characteristic in service.characteristics:
print(f" Characteristic: {characteristic.uuid}, Handle: {characteristic.handle}")
device_address = "XX:XX:XX:XX:XX:XX" # Replace with your device's address
asyncio.run(discover_services_and_handles(device_address)) |
Can you please run with the following change so we can see which UUID is causing the problem? diff --git a/bleak/backends/winrt/client.py b/bleak/backends/winrt/client.py
index 3431d0b..003b3b7 100644
--- a/bleak/backends/winrt/client.py
+++ b/bleak/backends/winrt/client.py
@@ -706,7 +706,7 @@ class BleakClientWinRT(BaseBleakClient):
characteristics: Sequence[GattCharacteristic] = _ensure_success(
await FutureLike(service.get_characteristics_async(*args)),
"characteristics",
- f"Could not get GATT characteristics for {service}",
+ f"Could not get GATT characteristics for {service.uuid} ({service.attribute_handle})",
)
logger.debug("returned from get_characteristics_async") |
Thanks - Here is the output - On linux these are read correctly using the same code.
|
We had a hard-coded list of services know to return an access denied error when attempting to enumerate characteristics. However, since we don't know Windows internals, the list was not exhaustive and it could also change in the future. Instead, we can just check for the access denied error and skip any service that returns that error which should also handle additional services we don't know about yet. Fixes: #1291
Thanks. Could you please test #1294 to see if it fixed the problem? |
Thanks , was able to connect to the device successfully with this change. |
Great, thanks for testing! Yes, it seems Windows gives an error for services like this that are "owned" by the OS while other OSes just hide them completely. |
We had a hard-coded list of services know to return an access denied error when attempting to enumerate characteristics. However, since we don't know Windows internals, the list was not exhaustive and it could also change in the future. Instead, we can just check for the access denied error and skip any service that returns that error which should also handle additional services we don't know about yet. Fixes: #1291
bluetoothctl -v
) in case of Linux:Description
Failed to connect to device: Could not get GATT characteristics for <_bleak_winrt_Windows_Devices_Bluetooth_GenericAttributeProfile.GattDeviceService object at 0x00000206F9189750>: Access Denied
The same code works in Linux but issues seen in windows.
What I Did
Just attempting to connect to the BLE device . Below is the function I am using to connect.
Logs
Added logs below .
blelogs.txt
Also added the Wireshark logs :
GATT-Wireshark.zip
The text was updated successfully, but these errors were encountered: