2015-06-19 77 views
1

我想写一个简单的蓝牙服务器,接受来自我的HeartRate设备(蓝牙LE)的连接,但它总是会引发例外BlueCove with Bluez chucks“无法打开SDP会话[2]没有这样的文件或目录”

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] 

我正在我的代码的Arch Linux的计算机上,使用内核 “4.0.5-1拱#1 SMP PREEMPT”。 Java是OpenJDK的1.8.0_45版本,Bluecove的版本是2.1.1-SNAPSHOT-63。我已经安装了下列文物的BlueZ:

  1. 的bluez 5.30-1
  2. 的bluez固件1.2-8
  3. 的bluez-库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; 
} 

任何想法?

+0

您是否检查并完成了此处描述的要求? http://www.bluecove.org/bluecove-gpl/index.html –

回答

5

第一:我知道这是一个相当古老的帖子,但我经常通过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

希望我仍然可以帮助别人!

3

我现在已经为几天同样的问题,我也跟着Cyphargs指令,但后来我得到了新的问题,它说权限被拒绝说没有这样的文件或目录,而不是,然后我发现Arch Linux forum神奇的解决方案:

chmod 777 /var/run/sdp # this line has done the magic 
相关问题