aniketker / webiopi

Automatically exported from code.google.com/p/webiopi
0 stars 0 forks source link

sensor.py One Wire Temps below 10000 (5 chars) do not work #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Connect a Dallas (or any one wire temp sensor)
2. Cool the sensor down below 10 degrees C
3. Try to access the temperature via a rest query.

What is the expected output? What do you see instead?
Expected: A temperature
Instead: 
Error response
Error code: 403
Message: invalid literal for int() with base 10: '=5062'.

What version of the product are you using? On what operating system?
r894 on RaspberryPi

Please provide any additional information below.

I located the issue and was able to get it working again.  This is caused in 
the sensor.py file by the following:

    def __getCelsius__(self):
        data = self.read()
        lines = data.split("\n")
        if lines[0].endswith("YES"):
            temp = lines[1][-5:]
            return int(temp) / 1000.0

lines[1][-5:] is expecting 5 characters but when the sensor is below 10 degrees 
C it returns integers such as 9550.

I was able to fix it by doing the following strip of the = sign:

    def __getCelsius__(self):
        data = self.read()
        lines = data.split("\n")
        if lines[0].endswith("YES"):
            temp = lines[1][-5:]
            temp = temp.strip('=')
            return int(temp) / 1000.0

Thank you!
Kewlj1313

Original issue reported on code.google.com by kewlj1...@gmail.com on 14 Feb 2013 at 4:15

GoogleCodeExporter commented 9 years ago
Also thanks very much for your hard work on this! This is an awesome project 
and I will continue to assist where I can.

Original comment by kewlj1...@gmail.com on 14 Feb 2013 at 4:16

GoogleCodeExporter commented 9 years ago
can you add :
1) precise component ref
2) webiopi driver you used (OneWireTemp or DS*)
3) dump of /sys/bus/w1/devices/{device_id}/w1_slave when this error occurs 

Original comment by tro...@trouch.com on 14 Feb 2013 at 9:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
1) DS18B20
2) in my /etc/webiopi/config I used the following temp0 = DS18B20 
28-000004664d5f
I'm not sure what else you are looking for here on the driver info.
3)
pi@raspberrypi /sys/bus/w1/devices $ cat 
/sys/bus/w1/devices/28-000004664d5f/w1_slave
3e 00 4b 46 7f ff 02 10 51 : crc=51 YES
3e 00 4b 46 7f ff 02 10 51 t=3875

Again the reason for this error is because the temperature is below 10 degrees 
C.  The code fix I did above fixes the problem.

Thank you,
-Jason

Original comment by kewlj1...@gmail.com on 14 Feb 2013 at 12:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
ok, I did not well understood first time.
I will rather use :

i = lines[1].find('=')
temp = lines[1][i+1:]
return int(temp)

thanks for feedback, I will correct it later today.

Original comment by tro...@trouch.com on 14 Feb 2013 at 1:29

GoogleCodeExporter commented 9 years ago
Good idea on the fix because that will also handle when there are less than 4 
chars etc...

don't forget to divide by 1000.0

return int(temp)/1000.0

Original comment by JasonFli...@gmail.com on 14 Feb 2013 at 2:59

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r898.

Original comment by tro...@trouch.com on 14 Feb 2013 at 5:49