问题
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
回答1:
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
来源:https://stackoverflow.com/questions/59786226/how-to-setup-the-enviroment-that-bluepy-can-scan-without-sudo