I am trying to write a simple Bluetooth server that accepts an connection from my HeartRate-Device (bluetooth LE) but it always raises an exception
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]
I am running my code on an Arch Linux machine with kernel "4.0.5-1-ARCH #1 SMP PREEMPT".
Java is OpenJDK at version 1.8.0_45 and Bluecove is at version 2.1.1-SNAPSHOT-63. I've got the following BlueZ artifacts installed:
The Bluetooth dongle I am using is up and running and I can scan for my heart-rate device using hcitool -i hci0 lescan
. I am also running my code as the root user.
So, here is the piece of code that brings me trouble:
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;
}
Any ideas?
First: I know this is a rather old post, but I got here quite often through Google and I finally got it working on my machine.
To got it working we need to start the bluetooth daemon with the -C
(or --compat
) option. This is done by making the following change:
Open a terminal and enter
sudo nano /etc/systemd/system/bluetooth.target.wants/bluetooth.service
then change line
ExecStart=/usr/lib/bluetooth/bluetoothd
to
ExecStart=/usr/lib/bluetooth/bluetoothd -C
(simply adding the -C
option)
Now you need to restart the system daemons:
sudo systemctl daemon-reload
And finally restart the Bluetooth service:
sudo systemctl restart bluetooth
I found this solution here: RaspberryPi Forum: Bluetooth RFCOMM - Jessie
Hope I could still help someone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With