【问题标题】:rfcomm bluetooth permission denied error raspberry pirfcomm 蓝牙权限被拒绝错误树莓派
【发布时间】:2016-04-08 13:41:33
【问题描述】:

我正在使用蓝牙加密狗尝试将信息从 ubuntu 15.04 发送到运行最新 debian jessie 映像的 raspberry pi b+。我只是在关注http://people.csail.mit.edu/albert/bluez-intro/ 教程。我得到了简单的 RFCOMM 和 L2CAP 协议工作。我在运行 SDP 协议时遇到问题。服务器代码是 -

from bluetooth import *

server_sock = BluetoothSocket(RFCOMM)
server_sock.bind(("", PORT_ANY))
server_sock.listen(1)

advertise_service(server_sock, "SampleServer",service_classes=[SERIAL_PORT_CLASS], profiles=[SERIAL_PORT_PROFILE])

client_sock, client_info = server_sock.accept()

print "connection from: ", client_info

client_sock.send("PyBluez server says Hello!")
data = client_sock.recv(1024)
print "received: ", data

client_sock.close()
server_sock.close()

我得到的错误是 -

Traceback (most recent call last):
  File "rfcomm-server.py", line 7, in <module>
    advertise_service(server_sock, "SampleServer",service_classes=[SERIAL_PORT_CLASS], profiles=[SERIAL_PORT_PROFILE])
  File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 176, in advertise_service
    raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (13, 'Permission denied')

这是我采取的一些步骤-

Add the user 'pi' to lp group
run piscan on hciconfig hci0
Add --compat option to bluetoothd in bluetooth.service

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 你试过以root身份运行吗?
  • 我应该打自己的头。有时解决方案就是这么简单!
  • 如果 pip 安装在用户本地,则以 root 身份运行将不起作用。解决这个问题的最简单方法是sudo chmod o+rw /var/run/sdp。从这里开始,相应地改进它。没有嗡嗡声。这是直接的解决方案。

标签: bluetooth raspberry-pi


【解决方案1】:

sudo 完成了这项工作。

sudo python script.py

【讨论】:

    【解决方案2】:

    以 root 身份运行脚本有点用,但 it's not a good practice

    根据this thread,只需要调整/var/run/sdp文件(使用--compat开关时创建)的权限即可。

    所以,为了防止链接失效,我正在复制 dlech 的帖子并将其改编为 Raspberry Pi:

    1. 确保您的 pi 用户在 bluetooth 组中:

      $ cat /etc/group | grep bluetooth
      bluetooth:x:113:pi
      

      1.1。如果不是,请将pi 添加到bluetooth 组:

      $ sudo usermod -G bluetooth -a pi
      
    2. /var/run/sdp 文件的更改组:

      $ sudo chgrp bluetooth /var/run/sdp
      
    3. 要使更改在重新启动后保持不变:

      3.1。创建文件/etc/systemd/system/var-run-sdp.path,内容如下:

      [Unit]
      Descrption=Monitor /var/run/sdp
      
      [Install]
      WantedBy=bluetooth.service
      
      [Path]
      PathExists=/var/run/sdp
      Unit=var-run-sdp.service
      

      3.2。还有一个文件,/etc/systemd/system/var-run-sdp.service

      [Unit]
      Description=Set permission of /var/run/sdp
      
      [Install]
      RequiredBy=var-run-sdp.path
      
      [Service]
      Type=simple
      ExecStart=/bin/chgrp bluetooth /var/run/sdp
      

      3.3。最后,启动它:

      sudo systemctl daemon-reload
      sudo systemctl enable var-run-sdp.path
      sudo systemctl enable var-run-sdp.service
      sudo systemctl start var-run-sdp.path
      

    功劳归于用户dlech,他最初“想通了”。

    【讨论】:

    • 您需要修改服务文件以包含:ExecStartPost=/bin/chmod 662 /var/run/sdp。这对我有用
    • 我是否将此作为第三行添加到[Service]
    猜你喜欢
    • 2017-11-28
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    • 2019-12-19
    • 2013-04-09
    • 2016-12-07
    相关资源
    最近更新 更多