我正在尝试通过蓝牙将Raspberry Pi 3B +(运行raspbian)连接到PC(Windows 10)。
我的PC上有一个服务器脚本,看来运行正常。但是,运行客户端脚本时,我的pi无法连接。这是客户端脚本的输出:
Making socket...
Connecting...
Traceback (most recent call last):
File "bt_connect_test.py", like 6, in <module>
client_socket.connect(("10:F0:05:75:66:D7", 3))
File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (71, 'Protocol error')
你们都可以帮我吗?
这是客户端的代码:
from bluetooth import *
print("Making socket...")
client_socket = BluetoothSocket(RFCOMM)
print("Connecting...")
client_socket.connect(("10:F0:05:75:66:D7", 3))
print("connected. type stuff")
while True:
data = input()
if len(data) == 0: break
sock.send(data)
sock.close()
和服务器:
from bluetooth import *
server_sock=BluetoothSocket( RFCOMM )
print("Server socket succesfully created.")
server_sock.bind(("", 3))
server_sock.listen(1)
print("Socket bound and listening.")
client_sock, address = server_sock.accept()
print("Found client @%s" % address)
print("Getting data...")
try:
while True:
data = client_sock.recv(1024)
if len(data) == 0: break
print(data)
except IOError:
pass
print("disconnected")
client_sock.close()
server_sock.close()
print("all done")