我正在编写一个 Python 脚本来使用 Raspberry Pi 控制我的 Mindstorms NXT。我的问题是,NXT 有一个蓝牙密码。您可以更改密码但不能删除它。
我想知道如何使用密钥将 PyBluez 套接字连接到设备。
这是当前程序:
import bluetooth
import socket
target_name = "Jerry"
target_address = None
print "performing inquiry..."
nearby_devices = bluetooth.discover_devices()
print "found %d devices" % len(nearby_devices)
for bdaddr in nearby_devices:
if target_name == bluetooth.lookup_name( bdaddr ):
target_address = bdaddr
break
if target_address is not None:
print "found target bluetooth device with address ", target_address
else:
print "could not find target bluetooth device nearby"
bluesock= socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
bluesock.connect((target_address, 1))