首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >bluetooth.btcommon.BluetoothError:[Errno 2]没有这样的文件或目录

bluetooth.btcommon.BluetoothError:[Errno 2]没有这样的文件或目录
EN

Stack Overflow用户
提问于 2022-08-11 13:41:10
回答 1查看 538关注 0票数 0

我试图通过Python在Khadas板上使用pybluez连接到蓝牙设备(有点像Raspberry,aarch64)。

我已经手动将PyBluez更新为5.65,因为它包含我需要的修补程序。bluetoothctl --versionbluetoothd --version都返回5.65。

一启动我的脚本,我就得到

代码语言:javascript
运行
复制
> python main.py
...
  File "/home/khadas/env/lib/python3.8/site-packages/bluetooth/bluez.py", line 271, in advertise_service
    _bt.sdp_advertise_service (sock._sock, name, service_id, \
_bluetooth.error: (2, 'No such file or directory')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khadas/copilot/copilot/process/process.py", line 126, in run
    self._pre_run()
  File "/home/khadas/copilot/copilot/task/bluetooth_connector_task.py", line 55, in _pre_run
    bluetooth.advertise_service(
  File "/home/khadas/env/lib/python3.8/site-packages/bluetooth/bluez.py", line 275, in advertise_service
    raise BluetoothError (*e.args)
bluetooth.btcommon.BluetoothError: [Errno 2] No such file or directory

this之后,我编辑了/etc/systemd/system/dbus-org.bluez.service/lib/systemd/system/bluetooth.service

代码语言:javascript
运行
复制
ExecStart=/usr/libexec/bluetooth/bluetoothd -C

然后,我用

代码语言:javascript
运行
复制
sudo systemctl daemon-reload & sudo systemctl restart bluetooth & sudo sdptool add SP

但我的错误依然存在。

你们以前有没有遇到过这种情况?

谢谢你抽出时间:)

注意:这个线程表示,在sudo sdptool add SP之后,应该在/var/run/sdp上创建一个文件;它不是。

注意:蓝牙服务正在运行,但存在错误,即

代码语言:javascript
运行
复制
(env) khadas@khadas > systemctl status bluetooth.service            
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-08-11 13:23:09 UTC; 13min ago
       Docs: man:bluetoothd(8)
   Main PID: 14256 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 2932)
     Memory: 676.0K
     CGroup: /system.slice/bluetooth.service
             └─14256 /usr/libexec/bluetooth/bluetoothd -C

Aug 11 13:23:09 khadas systemd[1]: Starting Bluetooth service...
Aug 11 13:23:09 khadas bluetoothd[14256]: Bluetooth daemon 5.65
Aug 11 13:23:09 khadas systemd[1]: Started Bluetooth service.
Aug 11 13:23:09 khadas bluetoothd[14256]: Starting SDP server
Aug 11 13:23:09 khadas bluetoothd[14256]: src/sdpd-server.c:init_server() binding UNIX socket: Read-only file system
Aug 11 13:23:09 khadas bluetoothd[14256]: src/sdpd-server.c:start_sdp_server() Server initialization failed
Aug 11 13:23:09 khadas bluetoothd[14256]: Bluetooth management interface 1.14 initialized
Aug 11 13:23:09 khadas bluetoothd[14256]: src/adapter.c:reset_adv_monitors_complete() Failed to reset Adv Monitors: Unknown Command (0x01)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-23 12:45:48

如果升级,还必须更新系统服务配置,因为新配置在此场景中无法工作。如果运行sudo service bluetooth status,您将看到新配置无法正确启动SDP服务器:

代码语言:javascript
运行
复制
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-08-23 11:42:36 UTC; 10min ago
       Docs: man:bluetoothd(8)
   Main PID: 3773 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 2934)
     Memory: 2.1M
     CGroup: /system.slice/bluetooth.service
             └─3773 /usr/libexec/bluetooth/bluetoothd -C

Aug 23 11:42:36 biped12 systemd[1]: Starting Bluetooth service...
Aug 23 11:42:36 biped12 systemd[3773]: ConfigurationDirectory 'bluetooth' already exists but the mode is different. (File system: 755 ConfigurationDirectoryMode: 555)
Aug 23 11:42:36 biped12 bluetoothd[3773]: Bluetooth daemon 5.65
Aug 23 11:42:36 biped12 systemd[1]: Started Bluetooth service.
Aug 23 11:42:36 biped12 bluetoothd[3773]: Starting SDP server
Aug 23 11:42:36 biped12 bluetoothd[3773]: src/sdpd-server.c:init_server() binding UNIX socket: Read-only file system
Aug 23 11:42:36 biped12 bluetoothd[3773]: src/sdpd-server.c:start_sdp_server() Server initialization failed
Aug 23 11:42:36 biped12 bluetoothd[3773]: Bluetooth management interface 1.14 initialized
Aug 23 11:42:36 biped12 bluetoothd[3773]: src/adapter.c:reset_adv_monitors_complete() Failed to reset Adv Monitors: Unknown Command (0x01)

要解决这个问题,您必须将配置更改为:

代码语言:javascript
运行
复制
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd -C
NotifyAccess=main
#WatchdogSec=10
Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
ProtectHome=true
ProtectSystem=full

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73321721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档