[英]Python Bluetooth Passkey/Password Linux
I'm working on a Python script to control my Mindstorms NXT with a Raspberry Pi. 我正在使用Python脚本来控制我的Mindstorms NXT和Raspberry Pi。 My problem is, that the NXT has a Bluetooth passkey.
我的问题是,NXT有一个蓝牙密码。 You can change the passkey but not delete it.
您可以更改密钥但不删除它。
I want to know how you can connect the PyBluez socket to a device with a passkey. 我想知道如何使用密钥将PyBluez套接字连接到设备。
This is the current program: 这是目前的计划:
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))
I'm not sure there's a Python specific answer. 我不确定是否有Python特定的答案。 The py-nxt posts I saw seemed to point at the OS.
我看到的py-nxt帖子似乎指向操作系统。
Does starting this background process (on your computer) with a passkey help you? 使用密钥启动此后台进程(在您的计算机上)可以帮助您吗?
bluetooth-agent 1234 &
I've found it useful to pair with the NXT first using: 我发现首先使用NXT配对很有用:
hcitool cc 00:16:53:0A:17:16
Whereby, I'd found the MAC address with: 据说,我找到了MAC地址:
hcitool scan
If you hadn't already tried the rfcomm related bits for Linux, there's a worthwhile ref here . 如果你还没有尝试过Linux的rfcomm相关位,那么这里有一个值得的参考。
On Windows, I just had to go into go into Bluetooth settings and pair with the device, entering the passkey on Windows and then on the NXT. 在Windows上,我只需要进入蓝牙设置并与设备配对,在Windows上输入密码,然后在NXT上输入密码。 It never showed a screen saying that it had paired, seemingly getting stuck pairing, but it did work and I was able to connect with nxt-python.
它从未显示屏幕说它已配对,似乎卡住配对,但它确实有效,我能够连接到nxt-python。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.