Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup the enviroment that bluepy can scan without sudo?

I wrote some Python3 script, that scans for devices. If they match a "name" I am connecting to them and do some ble stuff. The script is build on top of the bluepy module.

One think I don't like, is that I need to run the device scanning as sudo(like sudo python3 getDev.py). Any ideas how to make a user being able to scan without root rights?

Guess I need to add the local user to a group etc. Any ideas are welcome

like image 591
Stefan Jaritz Avatar asked Dec 04 '25 15:12

Stefan Jaritz


1 Answers

On linux Bluetooth protocol stack need special privileges to interact with.

These privileges are implemented through properties called capabilities, see man 7 capability for details.

The tool to assign capabilities is the program setcap.

In case of bluepy it is the binary bluepy-helper that interact with the bluetooth protocol stack, so locate where it is installed the package bluepy and run:

sudo setcap 'cap_net_raw,cap_net_admin+eip' ${PY_SITE_PACKAGES_DIR}/bluepy/bluepy-helper

See also here

like image 174
attdona Avatar answered Dec 07 '25 04:12

attdona



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!