【问题标题】:Establishing bluetooth connection between a J2ME application and a desktop application written with Python (preferably using pybluez)?在 J2ME 应用程序和用 Python 编写的桌面应用程序之间建立蓝牙连接(最好使用 pybluez)?
【发布时间】:2011-04-04 04:00:20
【问题描述】:

我正在尝试在我的 J2ME 应用程序(使用 JSR-082 API)和我用 Python 编写的桌面应用程序(使用 pybluez 蓝牙 API)之间建立蓝牙连接。但是,我找不到合适的蓝牙通信协议来配对它们。

在pybluez中,连接服务器的方式如下:

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

但是在 JSR-082 蓝牙 API 中,创建服务器的方式如下:

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

或如下:

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

在 pybluez API 中我们使用端口号,而在 JSR-082 API 中我们使用 URL。那我该如何建立蓝牙连接呢?有没有办法使用 JSR-082 API 中的端口号创建服务器?

【问题讨论】:

  • 我尝试做同样的事情,但我失败了。我建议您在手机(JSR 82)和计算机(BlueCove JSR 82 实现:bluecove.org)上都使用 Java

标签: java python java-me bluetooth jsr82


【解决方案1】:

使用 JSR-82,您可以基于 UUID 创建服务器。您需要执行 SDP 搜索以确定远程服务的“端口”(实际上是 RFCOMM 的通道号或 L2CAP 的 PSM)。因此,在 pybluez 中,您将调用 bluetooth.find_service()(如 here 所示),检查返回的每个服务,然后选择具有匹配 UUID 的服务(bluez 中的“service-id”)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    相关资源
    最近更新 更多