3

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

Stefan Jaritz
  • 1,999
  • 7
  • 36
  • 60

1 Answers1

5

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

attdona
  • 17,196
  • 7
  • 49
  • 60
  • Any ideas how to do that on Android, when using buildozer to build an kivy app? https://stackoverflow.com/questions/60319920/porting-a-python3-app-from-linux-to-android-using-kivy-and-bluepy – Stefan Jaritz Feb 24 '20 at 16:20