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

Usage in Python 3 without sudo #17

Closed
ralphbe91 opened this issue May 14, 2020 · 7 comments
Closed

Usage in Python 3 without sudo #17

ralphbe91 opened this issue May 14, 2020 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@ralphbe91
Copy link

Is it possible to use this library with Python 3 without sudo?

When I use "import mh_z19" and "mh_z19.read()" in my program it doesn't work. Although I have activated the serial port (just as you and others decribed ist), I get the following error: PermissionError: [Errno 13] Permission denied: '/dev/serial0'. The sensor is working, because when I use "$ sudo python -m mh_z19" I get the desired result.

I am a beginner in Python, that has already taken up a lot of my time.

@ralphbe91 ralphbe91 added the help wanted Extra attention is needed label May 14, 2020
@UedaTakeyuki
Copy link
Owner

Hi ralphbe91,

I'm afraid that the sudo might be necessary due to being required to read the serial port on RPi. I think your program calling mh_z19.read() also need the sudo to call without permission error.

@ralphbe91
Copy link
Author

Hi UedaTakeyuki . Oh, too bad. Thanks for your quick response and your effort. If anyone has a solution, I'd love to hear it.

@UedaTakeyuki
Copy link
Owner

Hi ralphbe91,

After considered deeply, I've got an idea to improve this library to use without root permission.
I'll try it and tell you the result soon.

By the way, would you please tell me the result of ls -la /dev/serial0?

@UedaTakeyuki
Copy link
Owner

UedaTakeyuki commented May 16, 2020

Hi ralphbe91,

I've updated this library for non-sudo support. Please refer here and try it. Thank you!

@ralphbe91
Copy link
Author

ralphbe91 commented May 17, 2020

Hi, thanks for your effort! But I have still the following problem:

pi@raspberrypi:~ $ sudo python3 -m mh_z19 
{"co2": 565}

Great!

pi@raspberrypi:~ $ python3 -m mh_z19 --serial_console_untouched
usage: __main__.py [-h]
                   [--serial_device SERIAL_DEVICE | --version | --all | --abc_on | --abc_off]
                   [--span_point_calibration SPAN_POINT_CALIBRATION]
                   [--zero_point_calibration] [--detection_range_5000]
                   [--detection_range_2000]
__main__.py: error: unrecognized arguments: --serial_console_untouched

Not that great...

I get the same error in my program when I use mh_z19.read(serial_console_untouched=True): TypeError: read() got an unexpected keyword argument 'serial_console_untouched'

Is there a problem with Python 3?

BTW:

pi@raspberrypi:~ $ ls -la /dev/serial0
lrwxrwxrwx 1 root root 5 Mai 17 16:13 /dev/serial0 -> ttyS0
pi@raspberrypi:~ $ ls -la /dev/ttyS0
crw-rw---- 1 root tty 4, 64 Mai 17 16:17 /dev/ttyS0

This should be fine.

Thanks!

@UedaTakeyuki
Copy link
Owner

Looks like the library you are using hasn't been updated. Would you please make sure the version?

pi@raspberrypi:~ $ python3 -m mh_z19 --version
0.5.1

The expected version is 0.5.1. Thank you!

@ralphbe91
Copy link
Author

Thats it!

After hours I got it working, thanks to your help. Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants