简体   繁体   中英

Establishing bluetooth connection between a J2ME application and a desktop application written with Python (preferably using pybluez)?

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM