【问题标题】:bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')bluetooth.btcommon.BluetoothError: (2, '没有这样的文件或目录')
【发布时间】:2016-08-09 03:00:56
【问题描述】:

我只是想在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')

我收到此错误。我的代码在 Windows 上运行,但我无法在 Ubuntu 15.10 上运行。

【问题讨论】:

  • 你安装过多次 BlueZ 包吗?

标签: bluetooth


【解决方案1】:

我在 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. service bluetooth restart
  • 示例rfcomm-server.py已经在充当串口应用程序,因此无需再做sudo sdptool add SP
【解决方案2】:

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

如果你有同样的经历;

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

# alternative: 
# sudo systemctl status bluetooth

在我的情况下,服务文件在 /lib/systemd/system/bluetooth.service 运行,而不是从 /etc/systemd/system/dbus-org.bluez.service 运行。

  • 然后修改正确的文件(原来是 /lib/systemd/system/bluetooth.service 在我的情况下)添加 -CExecStart=/usr/lib/bluetooth/bluetoothd 行中的说明 上一个答案。

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

sudo systemctl daemon-reload
sudo systemctl restart bluetooth

sudo sdptool add SP

现在应该生成/var/run/sdp

注意:如果您遇到权限错误,请检查以下答案:https://stackoverflow.com/a/42306883/4406572

【讨论】:

    【解决方案3】:

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

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

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

    内容如下:

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

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

    您必须创建目录。

    【讨论】:

    • 我在 Ubuntu 中测试了这个方法,它有效。 override.conf 文件确实做了覆盖。我可以看到/var/run/sdp 重启后自动创建的套接字文件。
    猜你喜欢
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 2015-11-19
    • 2013-03-21
    • 2015-04-09
    • 2019-05-26
    • 2018-12-06
    相关资源
    最近更新 更多