我正在使用蓝牙加密狗尝试将信息从ubuntu 15.04发送到raspberry pi b +运行最新的debian jessie图像。我只是关注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
任何帮助将不胜感激。谢谢!
答案 0 :(得分:14)
以root用户身份运行脚本有效,但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。
答案 1 :(得分:-1)
而sudo
完成了这项工作。
sudo python script.py