我正在使用蓝牙适配器尝试将信息从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
任何帮助将不胜感激。谢谢!
pip
安装是用户本地的,则以root身份运行将无法正常工作。解决这个问题的最简单方法是sudo chmod o+rw /var/run/sdp
。从这里开始,根据需要进行改进。没有任何麻烦。这是直接的解决方案。 - daparic