问题
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.
However the connection is established only when the two devices are paired. Is there an equivalent of listenUsingInsecureRfcommWithServiceRecord
in Python?
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
BluetoothDevice device = blueAdapter.getRemoteDevice(RPi_MAC);
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
blueAdapter.cancelDiscovery();
socket.connect();
回答1:
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.
Thanks for your inputs David!
来源:https://stackoverflow.com/questions/38477848/insecure-rfcomm-connection-in-python