Enviro+ (plus) Examples Error

Hi,

I recently purchased an Enviro+

It was deployed on a clean installation of Buster Lite with all the apt-get updates applied.

I can run most of the examples fine except for luftaten.py, all-in-one.py and all-in-one-no-pm.py
I get the following error which I cant work out:

all-in-one.py - Displays readings from all of Enviro plus’ sensors

Press Ctrl+C to exit!

Traceback (most recent call last):
File “all-in-one.py”, line 135, in
cpu_temp = get_cpu_temperature()
File “all-in-one.py”, line 89, in get_cpu_temperature
return float(output[output.index(’=’) + 1:output.rindex("’")])
TypeError: argument should be integer or bytes-like object, not ‘str’

Any hep the community could offer with this woule be dreatly appreciated.

Thank you…

I have the same problem but I am running debian stretch april 9 2019 release last release before buster.

python3 all-in-one-no-pm.py
all-in-one.py - Displays readings from all of Enviro plus’ sensors
Press Ctrl+C to exit!

Traceback (most recent call last):
File “all-in-one-no-pm.py”, line 126, in
cpu_temp = get_cpu_temperature()
File “all-in-one-no-pm.py”, line 83, in get_cpu_temperature
return float(output[output.index(’=’) + 1:output.rindex("’")])
TypeError: a bytes-like object is required, not ‘str’

It only happens when running the python3 command . if I run the python all-in-one-no-pm.py the board works it displays the sensor reading I just have to adjust from 0.8 compensation to 8.6

I guess the code is broken for python3

Hi,

So I managed to get to the bottom of this in the end:

The subprocess.communicate() type or _error can be either strings (what we want) or bytes. The type error message is the exact one that you get back when index() is called on a bytes object in a string argument.

Replace
output.index('=')
with
output.index(ord('='))

and

output.rindex("'")
with
output.rindex(ord("'"))

And the problem should be solved.

I must say that I find it a little bit disappointing that Pimoroni were not able to offer any support for their own product here and also that we are still waiting for the sound sensor library’s for the Enviro+.

The answer was provided over on Stack Exchange within a few hours by JSON Brody so any credit needs to go to him.

Thank you for your work and to JSON Brody

I applied the code change but there is still something not working when I try to run it in python3