如何设置bluepy无需sudo即可扫描的环境? [英] How to setup the enviroment that bluepy can scan without sudo?

查看:96
本文介绍了如何设置bluepy无需sudo即可扫描的环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些Python3脚本来扫描设备.如果它们与名称"匹配,我将连接到它们并做一些麻烦的事情.该脚本构建在 bluepy 模块的顶部.

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.

一个我不喜欢的地方是,我需要以 sudo (例如 sudo python3 getDev.py )运行设备扫描.有什么想法可以使用户能够在没有root权限的情况下进行扫描吗?

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

推荐答案

在linux上,蓝牙协议栈需要特殊的特权才能进行交互.

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

这些特权是通过称为功能的属性实现的,请参见 man 7功能以获得详细信息.

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

分配功能的工具是程序 setcap .

The tool to assign capabilities is the program setcap.

在使用bluepy的情况下,二进制 bluepy-helper 与蓝牙协议栈进行交互,因此找到安装了bluepy软件包的位置并运行:

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

另请参见此处

这篇关于如何设置bluepy无需sudo即可扫描的环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆