[英]Insecure rfcomm connection in Python
I would like to establish a bluetooth connection from an android device to a Raspberry Pi without pairing. 我想建立一个从android设备到Raspberry Pi的蓝牙连接而无需配对。 The language used in RPi is Python. RPi中使用的语言是Python。 I am connecting using createInsecureRfcommSocketToServiceRecord
from android. 我正在使用来自android的createInsecureRfcommSocketToServiceRecord
连接。
However the connection is established only when the two devices are paired. 但是,仅当两个设备配对时才建立连接。 Is there an equivalent of listenUsingInsecureRfcommWithServiceRecord
in Python? Python中是否有等效的listenUsingInsecureRfcommWithServiceRecord
?
Raspberry Pi code 树莓派代码
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 code Android代码
BluetoothDevice device = blueAdapter.getRemoteDevice(RPi_MAC);
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
blueAdapter.cancelDiscovery();
socket.connect();
I was able to connect to the Raspberry Pi without pairing. 我无需配对即可连接到Raspberry Pi。 For this I had to make the RPi discoverable. 为此,我必须使RPi易于发现。 Then I used socket.connect()
from my Nexus running on Marshmallow. 然后,我使用了在棉花糖上运行的Nexus上的socket.connect()
。 By doing this I was able to get the MAC address of my Nexus in the RPi. 这样,我就可以在RPi中获得Nexus的MAC地址。 Only problem is that I get a pairing request every time I connect but the MAC address was what I wanted. 唯一的问题是每次连接时都会收到一个配对请求,但MAC地址正是我想要的。
Thanks for your inputs David! 感谢您的输入,大卫!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.