问题描述
我想建立从Android设备到树莓派没有配对蓝牙连接。在RPI所使用的语言是Python。我使用 createInsecureRfcommSocketToServiceRecord
从Android的连接。
然而,当这两个设备配对的连接才成立。有 listenUsingInsecureRfcommWithServiceRecord
的等效Python中?
树莓派code
server_sock =的BluetoothSocket(RFCOMM)
server_sock.bind((,PORT_ANY))
server_sock.listen(1)
端口= server_sock.getsockname()[1]UUID =f3c74f47-1d38-49ed-8bbc-0369b3eb277cadvertise_service(server_sock,AquaPiServer
service_id为= UUID,
service_classes = [UUID,SERIAL_PORT_CLASS]
型材= [SERIAL_PORT_PROFILE]
) client_sock,CLIENT_INFO = server_sock.accept()
打印接受了连接,CLIENT_INFO
的Android code
BluetoothDevice类设备= blueAdapter.getRemoteDevice(RPi_MAC);
的BluetoothSocket插座= device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(\"f3c74f47-1d38-49ed-8bbc-0369b3eb277c\"));
blueAdapter.cancelDiscovery();
socket.connect();
我是能够连接到树莓派不配对。为此,我不得不作出的RPI发现。然后我用 socket.connect()
从棉花糖运行我的Nexus。通过这样做,我能得到我的Nexus的MAC地址在RPI。唯一的问题是,每次我得到的配对请求我连接,但MAC地址是我想要的。
感谢您的输入大卫!
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();
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!
这篇关于在Python不安全RFCOMM连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!