hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.81k stars 300 forks source link

DeviceNotFound & Could not get GATT services "Unreachable" #1217

Open ztroop opened 1 year ago

ztroop commented 1 year ago

Description

I maintain a library that uses bleak as a dependency and I have a Windows user that is experiencing failures with connectivity. After spending time examining bleak code, I don't see any smoking guns.

Traceback (most recent call last):
  File "C:\Users\username\OneDrive\Desktop\Github\PIPHI-CLI-v2\venv\lib\site-packages\bleak\backends\winrt\client.py", line 643, in get_services
    services: Sequence[GattDeviceService] = _ensure_success(
  File "C:\Users\username\OneDrive\Desktop\Github\PIPHI-CLI-v2\venv\lib\site-packages\bleak\backends\winrt\client.py", line 120, in _ensure_success
    raise BleakError(f"{fail_msg}: Unreachable")
bleak.exc.BleakError: Could not get GATT services: Unreachable

Any thoughts/suggestions/comments would be appreciated!

dlech commented 1 year ago

"Unreachable" comes from the Windows Bluetooth stack, so Bluetooth packet capture would be the best way to investigate that.

There are many issues that mention this error that might provide more insight as well: https://github.com/search?q=repo%3Ahbldh%2Fbleak+Unreachable&type=issues

dlech commented 1 year ago

I found an old issue #60 that suggests that a retry may help with this particular error. Can you add a retry to your code and see if it helps? If it does, we can look at adding an automatic retry in Bleak.

ztroop commented 1 year ago

I'll recommend that action once the user responds. As of this moment, I'm still waiting for a packet capture.

anikseng commented 1 month ago

I was able to connect to the BLE device once and after that it gives me this error "bleak.exc.BleakError: Could not get GATT services: Unreachable". I tried every possible solution but still the error is there.

joeygold commented 1 month ago

Try one of the silicon vendor BLE App's to confirm you can connect with the BLE device.

The connection with one of these App should be able to identify the services and characteristics.... you might have a digit wrong in your service or characteristic.

On Wed, 11 Sept 2024 at 20:04, anikseng @.***> wrote:

I was able to connect to the BLE device once and after that it gives me this error "bleak.exc.BleakError: Could not get GATT services: Unreachable". I tried every possible solution but still the error is there.

— Reply to this email directly, view it on GitHub https://github.com/hbldh/bleak/issues/1217#issuecomment-2343199976, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD37L4DCP6I4V2K6N54V55LZWAIRVAVCNFSM6AAAAABOATDVZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBTGE4TSOJXGY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Joey +61 412 750 765

dlech commented 1 month ago

IIRC, the "Unreachable" error usually happens because the Windows Bluetooth stack is waiting for a response for something that never comes from the device. The only way to find the source of the problem is to log Bluetooth packets as described in the troubleshooting page of the Bleak docs.