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

你。 提交于 2021-02-11 13:49:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!