【发布时间】:2019-11-02 06:40:43
【问题描述】:
我一直在尝试使用我的 raspberry-pi 从 PolarH10 获取数据。我已经通过 bluez 的命令行成功获取数据,但无法在 python 中重现。我正在使用 pygatt(gatttool bindings) 和 python3。
我一直密切关注bitbucket 上提供的示例,并且能够检测到我的设备并通过按名称过滤来过滤掉它的 MAC 地址。但是,我无法让“异步读取数据”示例中的任何一个工作。
#This doesnt work...
req = gattlib.GATTRequester(mymac)
response = gattlib.GATTResponse()
req.read_by_handle_async(0x15, response) # what does the 0x15 mean?
while not response.received():
time.sleep(0.1)
steps = response.received()[0]
...
#This doesn't work either
class NotifyYourName(gattlib.GATTResponse):
def on_response(self, data):
print("your data is: {}".format(data))
response = NotifyYourName()
req = gattlib.GATTRequester(mymac)
req.read_by_handle_async(0x15, response)
while True:
# here, do other interesting things
time.sleep(1)
我不知道也无法从“文档”中提取如何订阅/读取来自我的传感器(PolarH10)的特征(心率)的通知。我得到的错误是调用GATTRequester.connect(True) 时是
RuntimeError: Channel or attrib not ready.
请告诉我如何在 Debian 上通过 Python 正确连接到 BLE 设备,如何以编程方式识别提供的服务及其特征,以及如何使用 gattlib(pygatt) 或任何其他库在 python 中异步获取它们的通知。谢谢!
【问题讨论】:
标签: python-3.x bluetooth-lowenergy raspberry-pi3 gatt