I am trying to establish a bluetooth connection between my J2ME application (using JSR-082 API) and my desktop application written with Python (using pybluez bluetooth API). However, I could not find a suitable bluetooth communication protocols to pair them.

In pybluez, the way you connect to a server is as follows:

addr, port = "01:23:45:67:89:AB", 1
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((addr, port))

However in JSR-082 bluetooth API, the way you create a server is as follows:

StreamConnectionNotifier connectionNotifier =
    (StreamConnectionNotifier) Connector.open("btspp://localhost:" + 
    "0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();

or as follows:

L2CAPConnectionNotifier connectionNotifier = 
    (L2CAPConnectionNotifier) Connector.open("btl2cap://localhost:" + 
    "0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();

In pybluez API we use port numbers, and in JSR-082 API we use URLs. How am I going to establish a bluetooth connection then? Is there a way to create a server using a port number in JSR-082 API?

1

There are 1 answers

0
pwc On

Using JSR-82, you create a server based on a UUID. You need to perform an SDP search to determine the "port" (actually, channel number for RFCOMM or PSM for L2CAP) of the remote service. So, in pybluez, you'd call bluetooth.find_service() (as shown here), examine each of the services returned, and pick the one with a matching UUID ("service-id" in bluez).