Closed bggardner closed 4 years ago
Do you mind changing the source a little for your installation - so that data[0].strip()
and the [-3:]
is done on different lines and log the individual results? Like the contents of data
, data[0].strip()
?
I added some logging to print data
and its length. I'll post the results, but it will probably take a while. I suspect data
is an empty string...maybe the read occurs right when the OS is trying to write to the file?
maybe the read occurs right when the OS is trying to write to the file?
I'm not really sure how atomic that operation is on /sys
. Might be the case though.
Or maybe a defective connection or something similar could cause this.
I can confirm that data is an empty list ([]
) when this exception is thrown. I do not know the cause, but how should we handle it? Assume the sensor is not ready and add len(data) == 0
to the if
statement?
Assume the sensor is not ready and add
len(data) == 0
to theif
statement?
Yes, that's an option. I'm wondering if it should retry a few times (honestly, I'd rather not) - because as you report it's sporadic and it'll recover again.
For the time being though I'd recommend to raise the exception.
Can you try another installation to see if your connections are a problem? I've never had this issue myself ...
Hi I use Python try..except block. It is works fine with ver.1.0.5
from w1thermsensor import W1ThermSensor import time
sensor = W1ThermSensor()
while True: try: temperature_in_celsius = sensor.get_temperature(W1ThermSensor.DEGREES_C) print("celsius: {0:.3f}".format(temperature_in_celsius)) except IndexError as e: print(e) print(type(e))
finally:
time.sleep(5.0)
I have four DS18B20 sensors on the 1-wire network of a Raspberry Pi. After a long time (multiple hours, actual time may vary) of calling
get_temperature()
every 30 seconds in a while loop, I get anIndexError
with the following trace:After I restart the script, everything is happy, but it eventually occurs again. I will be adding some logging and updating this issue as I discover more. Any guidance is appreciated.
Environment and Version