bluetooth.btcommon.BluetoothError:(2,'没有这样的文件或目录')

Gul*_*lke 12 bluetooth

我只是想在https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py上运行RFCOMM服务器示例

$ 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')
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误.我的代码正在使用Windows,但我无法使用Ubuntu 15.10.

Goz*_*Man 10

我在Raspbian上遇到了同样的问题,并通过以下方式解决:

  • 以兼容模式运行蓝牙,

    通过修改/etc/systemd/system/dbus-org.bluez.service

    改变中

    ExecStart=/usr/lib/bluetooth/bluetoothd

    进入

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

  • 然后添加串行端口配置文件,执行: sudo sdptool add SP

参考文献:

  • 执行此操作后,请确保运行以下命令:1. systemctl daemon-reload 2.服务蓝牙重启 (4认同)

bka*_*lli 9

即使在 @GozzoMan 的解决方案之后我也遇到了同样的问题,因为/var/run/sdp在调用sudo sdptool add SP. 问题是守护程序服务文件的位置在我的系统上不同(Raspberry Pi 上的 Raspbian Buster)。

如果你也有同样的经历;

  • 检查蓝牙守护进程的状态并查找服务文件路径(第二行)
sudo service bluetooth status

# alternative: 
# sudo systemctl status bluetooth
Run Code Online (Sandbox Code Playgroud)

就我而言,服务文件运行于/lib/systemd/system/bluetooth.service,而不是 FROM /etc/systemd/system/dbus-org.bluez.service

蓝牙服务状态

  • 然后修改正确的文件( /lib/systemd/system/bluetooth.service在我的例子中)以按照前面的答案中的说明添加-C到该行。ExecStart=/usr/lib/bluetooth/bluetoothd

  • 在运行 sdptool 之前,不要忘记重新加载守护进程并重新启动蓝牙服务:

sudo systemctl daemon-reload
sudo systemctl restart bluetooth

sudo sdptool add SP
Run Code Online (Sandbox Code Playgroud)

现在/var/run/sdp应该已经生成了。

注意:如果您遇到权限错误,请检查以下答案:/sf/answers/2961481841/


sch*_*ter 7

关于编辑服务文件的答案有效,但每次更新都会中断。

正确的方法是在文件中添加覆盖

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

包含以下内容:

[Service]
ExecStart=
ExecStart=/usr/lib/bluetooth/bluetoothd -C
Run Code Online (Sandbox Code Playgroud)

第一行清除现有的 ExecStart,第二行添加正确的 ExecStart。

您必须创建该目录。