java - 带 Bluez 卡盘的 BlueCove "Can not open SDP session. [2] No such file or directory"

标签 java bluetooth-lowenergy

我正在尝试编写一个简单的蓝牙服务器,它接受来 self 的心率设备(蓝牙 LE)的连接,但它总是引发异常

javax.bluetooth.ServiceRegistrationException: Can not open SDP session. [2] No such file or directory
at com.intel.bluetooth.BluetoothStackBlueZ.openSDPSessionImpl(Native Method) ~[bluecove-gpl-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.BluetoothStackBlueZ.getSDPSession(BluetoothStackBlueZ.java:518) ~[bluecove-gpl-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.BluetoothStackBlueZ.registerSDPRecord(BluetoothStackBlueZ.java:543) ~[bluecove-gpl-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.BluetoothStackBlueZ.rfServerOpen(BluetoothStackBlueZ.java:607) ~[bluecove-gpl-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.BluetoothRFCommConnectionNotifier.<init>(BluetoothRFCommConnectionNotifier.java:42) ~[bluecove-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:389) ~[bluecove-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:156) ~[bluecove-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at javax.microedition.io.Connector.open(Connector.java:83) ~[bluecove-2.1.1-SNAPSHOT-63.jar:2.1.1-SNAPSHOT]
at com.mmazurcz.bluetoothserver.WaitThread.waitForConnection(WaitThread.java:39) [classes/:na]
at com.mmazurcz.bluetoothserver.WaitThread.run(WaitThread.java:60) [classes/:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]

我在内核为“4.0.5-1-ARCH #1 SMP PREEMPT”的 Arch Linux 机器上运行我的代码。

Java 是版本 1.8.0_45 的 OpenJDK,而 Bluecove 的版本是 2.1.1-SNAPSHOT-63。我已经安装了以下 BlueZ 工件:

  1. 布鲁兹 5.30-1
  2. bluez 固件 1.2-8
  3. bluez-libs 5.30-1
  4. bluez-utils 5.30-1

我正在使用的蓝牙加密狗已启动并正在运行,我可以使用 hcitool -i hci0 lescan 扫描我的心率设备。我还以 root 用户身份运行我的代码。

所以,这是给我带来麻烦的一段代码:

StreamConnectionNotifier notifier;
StreamConnection connection = null;

// setup the server to listen for connection
try {
    local = LocalDevice.getLocalDevice();
    log.info("Set up local device with BT address: " + local.getBluetoothAddress());
    local.setDiscoverable(DiscoveryAgent.GIAC);
    log.info("Set local device to GIAC discovery mode");

    UUID uuid = new UUID("1101", true);
    String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
    notifier = (StreamConnectionNotifier) Connector.open(url);
} catch (Exception e) {
    log.error("Exception in WaitThread.waitForConnection", e);
    return;
}

有什么想法吗?

最佳答案

首先:我知道这是一篇相当老的文章,但我经常通过 Google 访问这里,最后我终于让它在我的机器上运行了。

要使其正常工作,我们需要使用 -C(或 --compat)选项启动蓝牙守护进程。这是通过进行以下更改来完成的:

打开终端并输入

sudo nano /etc/systemd/system/bluetooth.target.wants/bluetooth.service

然后换行

ExecStart=/usr/lib/bluetooth/bluetoothd

ExecStart=/usr/lib/bluetooth/bluetoothd -C

(只需添加 -C 选项)

现在您需要重新启动系统守护进程:

sudo systemctl daemon-reload

最后重启蓝牙服务:

sudo systemctl restart bluetooth

我在这里找到了这个解决方案:RaspberryPi Forum: Bluetooth RFCOMM - Jessie

希望我还能帮到别人!

关于java - 带 Bluez 卡盘的 BlueCove "Can not open SDP session. [2] No such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30946821/

相关文章:

iOS 解释 BLE 数据和字节 swift 3

android - mBluetoothGatt.getService(uuid) 返回 null

java - 无法在 Spring Boot 应用程序中实例化 session 工厂

java - Apache commons IO 如何将我的 XML header 从 UTF-8 转换为 UTF-16?

java - Java 中的 AutoCAD 库读取 .dwg 文件?

java - 用于 Java 中的 Twitter 客户端的漂亮 GUI

c++ - Arduino ESP32 如何将 BLEUUID 对象分配给字符串

android - 需要在 Android ICS 上使用摩托罗拉 GATT 配置文件 API 的蓝牙低功耗示例

ios - 如何在后台扫描 BLE 设备?

java - 如何从 JavaBean(域类)中的属性文件读取值?