rfcomm 蓝牙权限被拒绝错误树莓派 [英] rfcomm bluetooth permission denied error raspberry pi
问题描述
我正在使用蓝牙加密狗尝试将信息从 ubuntu 15.04 发送到运行最新 debian jessie 映像的 raspberry pi b+.我只是在关注 http://people.csail.mit.edu/albert/bluez-intro/ 教程.我得到了简单的 RFCOMM 和 L2CAP 协议.我在运行 SDP 协议时遇到问题.服务器代码是 -
I'm using a bluetooth dongle to try and send information from ubuntu 15.04 to raspberry pi b+ running the latest debian jessie image. I'm just following the http://people.csail.mit.edu/albert/bluez-intro/ tutorial. I got the simple RFCOMM and L2CAP protocols working. I'm having trouble running the SDP protocol. The server code is -
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')
这是我采取的一些步骤-
Here are some steps I have taken-
Add the user 'pi' to lp group
run piscan on hciconfig hci0
Add --compat option to bluetoothd in bluetooth.service
任何帮助将不胜感激.谢谢!
Any help would be appreciated. Thanks!
推荐答案
以 root 身份运行脚本有点可行,但是 这不是一个好习惯.
Running your script as root kinda works, but it's not a good practice.
根据本帖,您只需要调整权限即可/var/run/sdp
文件(在使用 --compat
开关时创建).
According to this thread, you just need to adjust permissions to the /var/run/sdp
file (which is created when using the --compat
switch).
因此,为了防止链接失效,我正在复制 dlech 的帖子并将其调整到 Raspberry Pi:
So, to prevent link rot I'm reproducing dlech's post and adapting it to Raspberry Pi:
确保您的
pi
用户在bluetooth
组中:
$ cat /etc/group | grep bluetooth
bluetooth:x:113:pi
1.1.如果不是,将 pi
添加到 bluetooth
组:
1.1. If it's not, add pi
to bluetooth
group:
$ sudo usermod -G bluetooth -a pi
更改/var/run/sdp
文件的组:
$ sudo chgrp bluetooth /var/run/sdp
要在重启后使更改持久化:
To make the change persistent after reboot:
3.1.使用以下内容创建文件 /etc/systemd/system/var-run-sdp.path
:
3.1. Create file /etc/systemd/system/var-run-sdp.path
with the following content:
[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
:
3.2. And another file, /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.最后,开始吧:
3.3. Finally, start it all up:
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.
Credit goes to user dlech who "figured it out" originally.
这篇关于rfcomm 蓝牙权限被拒绝错误树莓派的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!