Issue #068 [Fixed/closed] - Temperature Exception when 1-Wire returns None

Posted by cazauxfrederick

What steps will reproduce the problem?

  1. Don't know exactly. The script and html attached. After a while (like 2h30), the server is still running but the loop does not run anymore. Don't have any error in log. Could it be too much HTTP requests ? But HTTP requests still work. 2. 3. ...

WebIOPi version used? => 0.6

Python version used? => 0.6 included

Distro used? (WebIOPi has only been tested on Raspbian Wheezy) => Raspbian Wheezy

Raspberry Pi board revision? (1 or 2) =>Rev 2

For Javascript side bugs, Browser? =>Chrome for Windows and Chrome for Androïd

Please provide any additional information below.

Thanx for your help!

Files attached

Comment 1

Posted by cazauxfrederick

Sorry, error in title : Script STOPS looping!

Comment 2

Posted by cazauxfrederick


Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.2/", line 740, in _bootstrap_inner File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/", line 78, in run self.func() File "/usr/share/webiopi/htdocs/thermostat/", line 40, in loop tempc = round(tmp.getCelsius()-1, 1)

TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

So, i guess this is what happens too when in background. I just wonder why I can't see it in /var/log/webiopi ?

But I have a temporary solution to try : add an exception on getCelcius() method in order it doesn't stop if an error occurs with it.

I'll let you know about next steps...

Comment 3

Posted by trouch

1-Wire sensors sometimes does not work. You have to test the result before using it :

temp = tmp.getCelsius() if (temp != None): tempc = round(temp-1, 1) ...

Comment 4

Posted by davidpaulmiller

Question: Is the exception occurring in the assigning of tempc, or the calling of tmp.getCelsius()? If it occurs in tmp.getCelsius(), it is too late for us to test the result before using it at our code level, it already has failed... I think has the right idea in adding an exception to getCelsius() method.

Comment 5

Posted by trouch

your stack trace is self explaining getCelsius returns None, without throwing any error. your error occur then, when your trying to do None-1 (temp being replaced by its value which is None)

Comment 6

Posted by cazauxfrederick

Yep... So I've added an exception on "tempc = round(tmp.getCelcius()-1, 1)". And that does the trick ! The tempc keeps its last value when the error occurs and doesn't affect the rest of the script. I've also added a variable in which I log the time of errors. That let me see that it happens compeletly randomly (or at least I can't figure a situation where it occurs).

Thank you for your help...

I still don't understand why I couldn't see those errors in the "/var/log/webiopi" when the script ran in background. What's the difference between the stack displayed in foreground and what is stored in the log file ?

Comment 7

Posted by davidpaulmiller

Interesting - I don't know if you notice in my exception *(issue 66) that it looks as though the exception is thrown in the Celsius2Fahrenheit call:

File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.6.0-py3.2-linux-armv6l.egg/webiopi/devices/sensor/", line 93, in Celsius2Fahrenheit return value * 1.8 + 32 TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

I've worked around my issue by calling getCelsius(), adding the test for null, and then converting to Fahrenheit myself -

Comment 8

Posted by trouch


Comment 9

Posted by trouch

Comment 10

Posted by trouch

Comment 11

Posted by trouch

temporarly fixed by r1421 - 1-Wire sensors return extremely low temperature instead of None when reading error occurs