20

I'm simply trying to run the RFCOMM server example at https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py

$ python2 rfcomm-server.py
Traceback (most recent call last):
  File "rfcomm-server.py", line 20, in <module>
    profiles = [ SERIAL_PORT_PROFILE ],
  File "/usr/lib/python2.7/site-packages/bluetooth/bluez.py", line 176, in advertise_service
    raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')

I am getting this error. My code is working on windows but I could not work Ubuntu 15.10.

Falko
  • 17,076
  • 13
  • 60
  • 105
Gulcan Ulke
  • 201
  • 1
  • 2
  • 4

3 Answers3

21

I had the same problem on Raspbian, and solved by:

  • Running bluetooth in compatibility mode,

    by modifying /etc/systemd/system/dbus-org.bluez.service,

    changing

    ExecStart=/usr/lib/bluetooth/bluetoothd

    into

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

  • Then adding the Serial Port Profile, executing: sudo sdptool add SP

References:

GozzoMan
  • 782
  • 9
  • 23
  • 6
    Make sure you run the following after doing this: 1. systemctl daemon-reload 2. service bluetooth restart – Rob Mascaro Nov 12 '18 at 04:37
  • 1
    The example `rfcomm-server.py` is already acting as the serial port application so there is no more need to do `sudo sdptool add SP`. – daparic Oct 14 '21 at 14:55
  • This helped, but in my case I also had to run my Python script as superuser. – Karolis Jun 20 '23 at 16:32
7

I ran the same problem even after @GozzoMan's solution because /var/run/sdp file was not being generated at all after calling sudo sdptool add SP. The problem was the location of daemon service file was different on my system (Raspbian Buster on Raspberry Pi).

If you experience the same;

  • Check the status of bluetooth daemon and look for the service file path (2nd line)
sudo service bluetooth status

# alternative: 
# sudo systemctl status bluetooth

In my case the service file was run at /lib/systemd/system/bluetooth.service, NOT FROM /etc/systemd/system/dbus-org.bluez.service.

bluetooth service status

  • Then modify the correct file (which was /lib/systemd/system/bluetooth.service in my case) to add -C to the ExecStart=/usr/lib/bluetooth/bluetoothd line as instructed in the previous answer.

  • Do not forget to reload daemons and restart bluetooth service before running sdptool:

sudo systemctl daemon-reload
sudo systemctl restart bluetooth

sudo sdptool add SP

Now /var/run/sdp should be generated.

Note: If you experience permission errors, check the following answer: https://stackoverflow.com/a/42306883/4406572

bkakilli
  • 498
  • 6
  • 12
3

The answer about editing the service file works, but breaks on every update.

The correct way is to add an override to the file

/etc/systemd/system/bluetooth.service.d/override.conf

with the following content:

[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd -C

The first line clears the existing ExecStart, the second line adds the correct one.

You will have to create the directory.

  • I tested this method in Ubuntu, it works. The `override.conf` file does indeed did an override. And I can see `/var/run/sdp` socket file auto-created after reboot. – daparic Oct 14 '21 at 14:06