python - Specific Android Bluetooth Server issue -


i have particular android bluetooth issue:

i have device (with no documentation) acts bluetooth client , tries connect (after pairing) bluetooth server listens using uuid "1234". have tested in advance using python script, device works , connects server. relevant code script is:

import bluetooth  uuid = "1234"  pc = bluetooth.bluetoothsocket(bluetooth.rfcomm)  pc.bind(("", bluetooth.port_any)) pc.listen(1)  port = pc.getsockname()[1] print 'active rfcomm port: ', port, '\r\n'  bluetooth.advertise_service( pc, "server",    service_id = uuid,    service_classes = [ uuid, bluetooth.serial_port_class ],    profiles = [ bluetooth.serial_port_profile ]  )  print 'waiting connection...\r\n' address = pc.accept() print 'accepting connection from: ', address, '\r\n' 

i trying create similar server on android using bluetoothserversocket. have converted 16-bit uuid ("1234"), according article, "00001234-0000-1000-8000-00805f9b34fb". have tested python script server valid , can connect using specified uuid. code used pretty standard, can found in many examples across internet:

@override public void run() {     bluetoothadapter adapter = bluetoothadapter.getdefaultadapter();      timber.i("start server");     try {         final bluetoothserversocket bluetoothserver = adapter.listenusingrfcommwithservicerecord("server", muuid);         timber.i("server started: " + muuid.tostring());          bluetoothsocket socket = bluetoothserver.accept();         timber.i("socket initiated: " + socket.getremotedevice().getname());          bluetoothserver.close();     } catch (ioexception e) {         timber.e("error starting server: " + e.getmessage());     } } 

i have tried both listenusingrfcommwithservicerecord , listenusinginsecurerfcommwithservicerecord. have made sure phone , device paired , phone discoverable. have tried different phones different os versions (2.3.7, 4.0.3, 4.4.2, 5.1.0), thought change of bluetooth stack in android 4.2 issue. nothing seems make device connect phone. can provide hci dump nexus 5 captured when device trying connect, wasn't able identify issue.

any appreciated.

edit:

this python code used verify android bluetooth server:

import sys import bluetooth  uuid = "1234" service_matches = bluetooth.find_service( uuid = uuid )  if len(service_matches) == 0:     print "couldn't find service"     sys.exit(0)  first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"]  print "connecting \"%s\" on %s" % (name, host)  sock = bluetooth.bluetoothsocket( bluetooth.rfcomm ) sock.connect((host, port)) sock.send("test") sock.close() 

needless worked without issues.

by off chance else runs type of issue, turns out bluetooth client device connecting server if had bluetooth device class, evidently not smart phone one.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -