不能 read/write 到 BLE 中的特性

Cannot read/write to characteristics in BLE

我有一个 BLED112 加密狗和一个 BLE 设备,其中包含具有服务特性的 GATT 配置文件。 我已经安装了 pygatt 来与我的 BLE 设备通信。

以下是我的 python 连接到我的 BLE 设备和 read/write 特征的代码:-

import pygatt
adapter = pygatt.BGAPIBackend()
#adapter = pygatt.BGAPIBackend()
adapter.start()
adapter.scan(timeout=1)
device = adapter.connect('30:F5:6A:01:2D:05',address_type=pygatt.BLEAddressType.public)
characteristic = "f1126ec4-6e99-5552-5286-55bc21d65776"
device.char_write(characteristic, bytearray([0x00]), wait_for_response=True)
value = device.char_read(characteristic)
print(value)
adapter.stop()

我可以连接到我的设备。 但是,我在阅读或写作时遇到以下错误:

C:\Python\Python37-32\lib\site-packages\pygatt\backends\bgapi\bgapi.py", line 570, in expect_any raise exc pygatt.backends.bgapi.exceptions.ExpectedResponseTimeout: Timed out after 10.000000s waiting for []

我已将 wait_for_response=True 包含在我的写入说明中,但我仍然遇到此问题。

如何read/write特征不报错?

PS: 扫描时发现上面的UUID属于"descriptor".

这是我收到错误的原因吗?

有没有办法在 pygatt 中写入 "descriptor"(而不是特征)?

终于把特征UUID改成特征句柄搞定了。 以下是工作代码:-

import pygatt
import time
adapter = pygatt.BGAPIBackend()
#adapter = pygatt.BGAPIBackend()
adapter.start()
adapter.scan(timeout=1)
device = adapter.connect('30:F5:6A:01:2D:05',address_type=pygatt.BLEAddressType.public)
characteristic = "26"
device.char_write_handle(characteristic, bytearray([0x00, 0x09]), wait_for_response=True)
time.sleep(2)
value = device.char_read_handle(characteristic)
print(value)
adapter.stop()