[英]Unable to Readspecific characteristic from BLE Device with python
当我用 python 扫描所有可用的特征时,我得到:
INFO:__main__:[Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 1): Generic Attribute
Profile
INFO:__main__: [Characteristic] 00002a05-0000-1000-8000-00805f9b34fb (Handle: 2):
(indicate), Value: None
INFO:__main__: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 4): Client
Characteristic Configuration) | Value: b'\x02\x00'
INFO:__main__:[Service] 00001800-0000-1000-8000-00805f9b34fb (Handle: 5): Generic Access
Profile
INFO:__main__: [Characteristic] 00002a00-0000-1000-8000-00805f9b34fb (Handle: 6):
(read,write-without-response,write,authenticated-signed-writes), Value: b'HRSTM'
INFO:__main__: [Characteristic] 00002a01-0000-1000-8000-00805f9b34fb (Handle: 8):
(read,write-without-response,write,authenticated-signed-writes), Value: b'@\x03'
INFO:__main__: [Characteristic] 00002a04-0000-1000-8000-00805f9b34fb (Handle: 10): (read),
Value: b'\xff\xff\xff\xff\x00\x00\xff\xff'
问题是我无法读取具有(指示)权限的特征。 我可以从上面读取任何具有读取权限的特性。 为什么我不能阅读那些具有指示权限的内容?
当我使用我的手机并连接到 BLE 时,我可以看到任何特性的值,即使是那些我无法通过 pc 读取的值。 (例如特征为句柄:1。
这是我的 Python 代码:
import sys
import platform
import asyncio
import logging
from bleak import BleakClient
logger = logging.getLogger(__name__)
UUID = "00002a04-0000-1000-8000-00805f9b34fb"
ADDRESS = (
"00:80:E1:26:C4:5E"
if platform.system() != "Darwin"
else "B9EA5233-37EF-4DD6-87A8-2A875E821C46"
)
async def main(address):
async with BleakClient(address) as client:
while True :
value = bytes(await client.read_gatt_char(UUID));
await asyncio.sleep(1, 0);
print(value)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
这是我运行上面的代码时得到的错误:
bleak.exc.BleakError: Could not read characteristic handle 2: Protocol Error 0x02: Read Not
Permitted
解决方案:
我发现我需要创建一些通知处理程序,这将使我能够从所选特征中读取日期
这是执行此操作的代码:
def notification_handler(sender, data):
"""Simple notification handler which prints the data received."""
output_numbers = list(data)
print(output_numbers)
async def main(address):
async with BleakClient(address) as client:
await client.start_notify(UUID, notification_handler)
await asyncio.sleep(10.0)
await client.stop_notify(UUID)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.