Python Gattlib按句柄读取函数:读取数据存储在哪里?

Python Gattlib按句柄读取函数:读取数据存储在哪里?,python,bluetooth,serial-port,raspberry-pi3,bluez,Python,Bluetooth,Serial Port,Raspberry Pi3,Bluez,这是我的第一个问题,我是工程师,不是程序员,所以请耐心听我说: 我正在尝试将数据从一个BLE设备拉到我的raspberry pi 3。BLE设备是一个HC 05模块,通过简单的Arduino脚本每1秒发送一次串行数据“9999” BlueZ 5.44似乎配置正确,因为我可以连接和断开连接而不会出现问题 有关图书馆的文件如下: 这是我的测试脚本: from __future__ import print_function import sys from gattlib import GATTRe

这是我的第一个问题,我是工程师,不是程序员,所以请耐心听我说:

我正在尝试将数据从一个BLE设备拉到我的raspberry pi 3。BLE设备是一个HC 05模块,通过简单的Arduino脚本每1秒发送一次串行数据“9999”

BlueZ 5.44似乎配置正确,因为我可以连接和断开连接而不会出现问题

有关图书馆的文件如下:

这是我的测试脚本:

from __future__ import print_function

import sys
from gattlib import GATTRequester, GATTResponse
import time


class Reader(object):
    def __init__(self, address):
        store=''
        self.requester = GATTRequester(address, False)
        self.connect()
        self.request_data()

    def connect(self):
        print("Connecting...", end=' ')

        self.requester.connect()
        print("OK!")

    def request_data(self):
        time.sleep(2)
        data = self.requester.read_by_handle(0x5)

        print (data)


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: {} <addr>".format(sys.argv[0]))
        sys.exit(1)

    Reader(sys.argv[1])
    print("Done.")
下列信息如下:

on notification, handle: 0x12 ->
是我要找的数据。ASCII“9999”的十六进制等效值

但是,这些信息是从pygattlib库中包含的C文件打印到控制台的

在我的代码中,我唯一可以访问的输出是:

['\x00\x00']
这显然不是我想要的数据


所以我的问题是:如何获得脚本中变量所需的数据?我只是想避免使用subprocess.Popen来获取控制台数据,而这对我来说似乎是完全不必要的。

我自己没有这个设备,我只是在尝试使用相同的API,但我认为您需要为地址0x12注册一个通知处理程序(退出控制台输出)而不是读取地址0x05

根据链接中的示例,它应该类似于

from gattlib import GATTRequester, GATTResponse

class NotifyYourName(GATTResponse):
    def on_response(self, name):
        print("your name is: {}".format(name))

response = NotifyYourName()
req = GATTRequester("00:11:22:33:44:55") # use your address here
req.read_by_handle_async(0x12, response)

while True:
    # here, do other interesting things
    sleep(1)

数据通常以列表的形式从
read\u by\u handle
方法返回(例如,当您读取寄存器时),因此您通常会使用类似
data=read\u by\u handle(0x05)[0]
,但是我认为对于一个自己发送通知的设备来说这是不同的。

我自己没有这个设备,我只是在试验相同的API,但我认为您希望为地址0x12注册一个通知处理程序(离开控制台输出),而不是读取地址0x05

根据链接中的示例,它应该类似于

from gattlib import GATTRequester, GATTResponse

class NotifyYourName(GATTResponse):
    def on_response(self, name):
        print("your name is: {}".format(name))

response = NotifyYourName()
req = GATTRequester("00:11:22:33:44:55") # use your address here
req.read_by_handle_async(0x12, response)

while True:
    # here, do other interesting things
    sleep(1)
数据通常以列表的形式从
read\u by\u handle
方法返回(例如,当您读取寄存器时),因此您通常会使用类似
data=read\u by\u handle(0x05)[0]
,但是我认为对于自行发送通知的设备来说这是不同的