我正在尝试通过BLE将数据从Bluno发送到Raspberry Pi(Raspian),bluez 5.50。
虽然连接似乎很好。我很震惊,无法从通知句柄中检索串行数据。
以下是我的尝试。
pi@raspberrypi:~ $ sudo gatttool -b <BLE-MAC-ADDRESS> -I
<BLE-MAC-ADDRESS>[LE]> connect
Attempting to connect to <BLE-MAC-ADDRESS>
Connection successful
[<BLE-MAC-ADDRESS>][LE]>
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>char-read-hnd 0x0025
handle : 0x0025 value : 01
Notification handle = 0x0025 value : 32
Notification handle = 0x0025 value : 32
[<BLE-MAC-ADDRESS>][LE]>
所以这里的问题是,通知句柄监听器'监听'串行数据并从Bluno每1秒返回一个值(2 - > Hex:32)(如Adurinosketch中编程)。
但是当我尝试通过命令char-read(由handle&amp; uuid尝试)检索此值时,它总是返回01?!!!
最终我想在我的Python代码中检索这个值(我正在使用Pexpect)
感谢任何帮助/指示。
答案 0 :(得分:0)
好的,这就是我最终在Python代码中所做的以获取值
`
child = pexpect.spawn("sudo gatttool -b <BLUNO-MAC-ADDR> -I")
# Connect to the device.
print("Connecting to Bluno...")
child.sendline("connect")
child.expect("Connection successful", timeout=5)
print(" Connected!")
while True:
child.expect("Notification handle = 0x0025 value: ", timeout=10)
child.expect("\r\n", timeout=10)
resp = child.before
print(process_my_data(bytearray.fromhex(resp.decode("utf-8")).decode()))
`