Rfcomm Bluetooth permission denied raspberry pi error

I am using a bluetooth dongle to try to send information from ubuntu 15.04 to raspberry pi b + using the latest debian jessie image. I just follow the tutorial http://people.csail.mit.edu/albert/bluez-intro/ . I got simple RFCOMM and L2CAP protocols. I have problems with the SDP protocol. Server Code -

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() 

The error I am getting is

 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 took -

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

Any help would be greatly appreciated. Thanks!

+5
source share
2 answers

Running the script as the root type works, but this is not a good practice .

According to this thread , you just need to configure permissions for the file /var/run/sdp (which is created using the --compat switch).

So, to prevent link rot, I play the dlech message and adapt it to Raspberry Pi:

  • make sure your pi user is in the bluetooth group:

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

    1.1. If this is not the case, add pi to the bluetooth group:

     $ sudo usermod -G bluetooth -a pi 
  • Change the group of the file /var/run/sdp :

     $ sudo chgrp bluetooth /var/run/sdp 
  • To make the change permanent after a reboot:

    3.1. Create the file /etc/systemd/system/var-run-sdp.path with the following contents:

     [Unit] Descrption=Monitor /var/run/sdp [Install] WantedBy=bluetooth.service [Path] PathExists=/var/run/sdp Unit=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. Finally, run everything:

     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 

The loan is sent to user dlech , who initially "understood".

+9
source

And sudo does the job.

 sudo python script.py 
-1
source

Source: https://habr.com/ru/post/1239833/


All Articles