Python 的蓝牙库的 Bleak 报告“bleak.exc.BleakError: Could not get GATT services: Unreachable” ,如何解决?

发布于 2025-01-17 03:43:28 字数 2668 浏览 3 评论 0原文

我是菜鸟,这几天无所事事,只好求助overflow(┬┬﹏┬┬)

Windows 10 下载bleak包的python第三方库和conda的虚拟环境tf- gpu-3.7本地安装它。

使用 bleak 的示例文件:https://github.com/hbldh/bleak /blob/develop/examples/get_services.py

可以正常获取蓝牙服务特征值。我就按照文档使用read_gatt_descriptor和read_gatt_char,Pycharm突然就报错了。 (此时我没有更改示例文件的代码)

错误:

C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 27, in <module>
    asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 19, in main
    async with BleakClient(address) as client:
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\client.py", line 61, in __aenter__
    await self.connect()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 276, in connect
    await self.get_services()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 456, in get_services
    "Could not get GATT services",
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 105, in _ensure_success
    raise BleakError(f"{fail_msg}: Unreachable")
bleak.exc.BleakError: Could not get GATT services: Unreachable

图片:https://tupian.li/images/2022/03/26/image4e67fd58c248b7b3.png

不知道怎么解决,错误太突然了。前段时间还好好的,现在不行了。

我重新创建了虚拟环境并重新安装了bleak,不幸的是错误又重复了。

ESP32重启了几次,pyCharm又写了几次,但都报同样的错误。前几天向作者求助,目前还没有回复……

ESP32代码:https://github.com/hbldh/bleak/files/8348469/BLE.UART.txt

捕获的蓝牙数据包:https://github.com/hbldh/bleak/files/8348459/ERROR.txt< /a>

如何解决突然出现的错误:无法获取 GATT 服务:无法访问

I'm a rookie, I've been doing nothing for a few days and have to turn to overflow for help (┬┬﹏┬┬)

Windows 10 downloads a python third-party library of the bleak package and conda's virtual environment tf-gpu-3.7 local install it.

Use bleak's example file:https://github.com/hbldh/bleak/blob/develop/examples/get_services.py

The bluetooth service characteristic value can be obtained normally. I will be according to the document using read_gatt_descriptor and read_gatt_char, Pycharm is suddenly the error. (I didn't change the code for example file at this point)

ERROR:

C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 27, in <module>
    asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 19, in main
    async with BleakClient(address) as client:
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\client.py", line 61, in __aenter__
    await self.connect()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 276, in connect
    await self.get_services()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 456, in get_services
    "Could not get GATT services",
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 105, in _ensure_success
    raise BleakError(f"{fail_msg}: Unreachable")
bleak.exc.BleakError: Could not get GATT services: Unreachable

Picture:https://tupian.li/images/2022/03/26/image4e67fd58c248b7b3.png

I don't know how to solve it.The error is too sudden. It was fine a while ago, but now it doesn't work.

I recreated the virtual environment and re-installed the bleak, and unfortunately the error was repeated.

ESP32 restarted several times, pyCharm wrote again several times, but they all reported the same error. A few days ago, I asked the author for help, but I haven't replied yet...

ESP32 Code:https://github.com/hbldh/bleak/files/8348469/BLE.UART.txt

Captured Bluetooth packets:https://github.com/hbldh/bleak/files/8348459/ERROR.txt

How to resolve the sudden error:Could not get GATT services: Unreachable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2025-01-24 03:43:29

抱歉,不清楚我将在哪里描述问题所在......

问题已经结束。找到错误原因:

ESP.restart();

忘记注释esp.restart函数,导致ESP32不断重启。因此无法获得蓝牙的服务。

Sorry, it's not clear where I will describe what is wrong...

The problem is over. I find the cause of the error:

ESP.restart();

I forgot to comment on the esp.restart function, causing ESP32 to keep rebooting. Therefore, the services of Bluetooth cannot be obtained.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文