Python 中不安全的 rfcomm 连接 [英] Insecure rfcomm connection in Python
问题描述
我想在不配对的情况下建立从 android 设备到 Raspberry Pi 的蓝牙连接.RPi 中使用的语言是 Python.我使用 createInsecureRfcommSocketToServiceRecord
从 android 连接.
I would like to establish a bluetooth connection from an android device to a Raspberry Pi without pairing. The language used in RPi is Python. I am connecting using createInsecureRfcommSocketToServiceRecord
from android.
然而,只有当两个设备配对时才能建立连接.Python 中是否有等效的 listenUsingInsecureRfcommWithServiceRecord
?
However the connection is established only when the two devices are paired. Is there an equivalent of listenUsingInsecureRfcommWithServiceRecord
in Python?
树莓派代码
server_sock=BluetoothSocket( RFCOMM )
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port = server_sock.getsockname()[1]
uuid = "f3c74f47-1d38-49ed-8bbc-0369b3eb277c"
advertise_service( server_sock, "AquaPiServer",
service_id = uuid,
service_classes = [ uuid, SERIAL_PORT_CLASS ],
profiles = [ SERIAL_PORT_PROFILE ],
)
client_sock, client_info = server_sock.accept()
print "Accepted connection from ", client_info
Android 代码
BluetoothDevice device = blueAdapter.getRemoteDevice(RPi_MAC);
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
blueAdapter.cancelDiscovery();
socket.connect();
推荐答案
我无需配对即可连接到 Raspberry Pi.为此,我必须使 RPi 可发现.然后我使用了运行在 Marshmallow 上的 Nexus 中的 socket.connect()
.通过这样做,我能够在 RPi 中获取我的 Nexus 的 MAC 地址.唯一的问题是我每次连接时都会收到配对请求,但 MAC 地址是我想要的.
I was able to connect to the Raspberry Pi without pairing. For this I had to make the RPi discoverable. Then I used socket.connect()
from my Nexus running on Marshmallow. By doing this I was able to get the MAC address of my Nexus in the RPi. Only problem is that I get a pairing request every time I connect but the MAC address was what I wanted.
感谢大卫的投入!
这篇关于Python 中不安全的 rfcomm 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!