我正在尝试将我的 Raspberry Pi 3B 连接到具有 HC-05 蓝牙芯片以发送命令的 Arduino。我已经使用 HC-05 和 Pi 成功配对
Device 98:7B:F3:57:76:34
Name: BT05
Alias: BT05
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000ffe0-0000-1000-8000-00805f9b34fb)
Modalias: bluetooth:v000Dp0000d0110
现在我正在尝试使用 Python 发送命令。我的代码是:
import bluetooth
bd_addr = "98:7B:F3:57:76:34"
def connect ():
port = 1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
print("Trying to pair to", bd_addr)
sock.connect((bd_addr, port))
a = "a"
while a != 'quit':
a = input("<<< ")
sock.send(a)
sock.close()
connect()
运行代码时出现异常,说主机宕机,找不到问题:
python3 tests/bt.py
Trying to pair to 98:7B:F3:57:76:34
Traceback (most recent call last):
File "<string>", line 3, in connect
_bluetooth.error: (112, 'Host is down')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tests/bt.py", line 16, in <module>
connect()
File "tests/bt.py", line 9, in connect
sock.connect((bd_addr, port))
File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (112, 'Host is down')
我尝试更换 HC-05 设备并重新启动蓝牙服务和 Pi,但我似乎仍然无法连接到 Arduino,我迷路了。
感谢所有帮助者