Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry pi 3B+ Python3, sudo privilege required #28

Open
beltsanderxyz opened this issue Jun 6, 2021 · 1 comment
Open

Raspberry pi 3B+ Python3, sudo privilege required #28

beltsanderxyz opened this issue Jun 6, 2021 · 1 comment

Comments

@beltsanderxyz
Copy link

I've got waveplus-reader working on my RPi 3B+ using Python3. I had to reformat the print statements, run in a virtual environment, and format my call "sudo python3 read_waveplus.py serial_number 60".

I am trying to figure out why sudo privileges are required and how to avoid needing that in the future. The error I get without sudo privilege is below:

Traceback (most recent call last): File "read_waveplus.py", line 221, in <module> waveplus.connect() File "read_waveplus.py", line 119, in connect devices = scanner.scan(0.1) # 0.1 seconds scan period File "/home/pi/MyEnv/waveplus/lib/python3.7/site-packages/bluepy/btle.py", line 734, in scan self.start(passive=passive) File "/home/pi/MyEnv/waveplus/lib/python3.7/site-packages/bluepy/btle.py", line 672, in start self._mgmtCmd("le on") File "/home/pi/MyEnv/waveplus/lib/python3.7/site-packages/bluepy/btle.py", line 283, in _mgmtCmd "Failed to execute mgmt cmd '%s'" % (cmd)) bluepy.btle.BTLEException: Failed to execute mgmt cmd 'le on'

@stiandre
Copy link

stiandre commented Nov 28, 2021

I had the same issue, and didn't want to run my python app with root privileges. I solved it by giving bluepy-helper the appropriate permissions to execute mgmt cmd: 'le on' by executing the following command:

sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper

It looks like you are using a virtual environment (MyEnv), and then you can just set it for bluepy-helper within that particular environment. I am using pyenv and poetry, so I made a tiny shell script to fix it:

#!/bin/sh

PROJECT_VENV=$(poetry env info -p)
sudo setcap 'cap_net_raw,cap_net_admin+eip' $PROJECT_VENV/lib/python3.10/site-packages/bluepy/bluepy-helper

@beltsanderxyz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants