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

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 kinda的身份运行脚本,但可以使用it's not a good practice

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

因此,为防止链接腐烂,我正在复制dlech的帖子,并将其调整为适用于Raspberry Pi:

  • 确保您的pi用户位于bluetooth组中:
    $ cat /etc/group | grep bluetooth
    bluetooth:x:113:pi
    

    1.1。如果不是,请将pi添加到bluetooth组:
    $ sudo usermod -G bluetooth -a pi
    
  • 更改/var/run/sdp文件的组:
    $ sudo chgrp bluetooth /var/run/sdp
    
  • 要使更改在重新启动后持久存在:

    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最初“弄清楚”的用户。

    关于bluetooth - rfcomm蓝牙许可被拒绝错误树莓派,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34599703/

    10-12 00:35