【问题标题】:Getting Data from PolarH10 via BLE通过 BLE 从 PolarH10 获取数据
【发布时间】: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


    【解决方案1】:

    我有一台呈现相同行为的设备。就我而言,问题在于它没有public 类型的通道,我应该改用random(如gatttool -b BE:BA:CA:FE:BA:BE -I -t random)。

    只要调用connect()方法,参数channel_typerandom就可以解决:

    requester.connect(True, channel_type="random")
    

    PD:很抱歉回复晚了(也许对其他人有帮助)。

    【讨论】:

      【解决方案2】:

      答案是:只需使用bleak

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-02
        • 2014-04-29
        • 2020-04-04
        相关资源
        最近更新 更多