android - How to connect pybluez RFCOMM server socket on Debian? -
i have these snippet in python pybluez framework:
from bluetooth import * server_sock=bluetoothsocket( rfcomm ) server_sock.bind(("",port_any)) server_sock.listen(1) port = server_sock.getsockname()[1] uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" advertise_service( server_sock, "sampleserver", service_id = uuid # service_classes = [ uuid, serial_port_class ], # profiles = [ serial_port_profile ], # protocols = [ rfcomm_uuid ] ) print "waiting connection on rfcomm channel %d" % port client_sock, client_info = server_sock.accept() print "accepted connection ", client_info try: while true: data = client_sock.recv(1024) if len(data) == 0: break print "received [%s]" % data except ioerror: pass print "disconnected" client_sock.close() server_sock.close() print "all done"
and have other snippet in android connect pybluez rfcomm server socket:
private static final uuid my_uuid = uuid.fromstring("94f39d29-7d6d-437d-973b-fba39e49d4ee"); .... bluetoothdevice device = mbluetoothadapter.getremotedevice(myservermacaddress); .... bluetoothsocket tmp= device.createinsecurerfcommsockettoservicerecord(my_uuid);
my problem android device not connect pybluez socket. think way use connect wrong, , don't know how connect correctly or advertise server socket
i offered bounty, found solution myself. :) posted on answer may apply problem. on versions of debian (raspbian etc) , maybe others distros. server_sock.accept()
default hang , never accept connection - paired device! i'm in cases convinced socket isn't open @ all. however, solution simple.
update /etc/bluetooth/main.conf file, add line or change existing looks this:
disableplugins = pnat
then restart bluetooth service:
sudo invoke –rc.d bluetooth restart
it may have been fixed.
good luck!
Comments
Post a Comment