diff py/sensor_ds18b20.py @ 151:e114b38c8a55

internal temperature sensor
author Matt Johnston <matt@ucc.asn.au>
date Thu, 20 Dec 2012 22:24:42 +0800
parents d686b111dab4
children d03157c7ad60
line wrap: on
line diff
--- a/py/sensor_ds18b20.py	Sun Dec 16 22:14:46 2012 +0800
+++ b/py/sensor_ds18b20.py	Thu Dec 20 22:24:42 2012 +0800
@@ -19,6 +19,19 @@
         self.readthread = gevent.threadpool.ThreadPool(1)
         self.master_dir = config.SENSOR_BASE_DIR
 
+    def do(self):
+        vals = {}
+        for n in self.sensor_names():
+                value = self.do_sensor(n)
+                if value is not None:
+                    vals[n] = value
+
+        itemp = self.do_internal()
+        if itemp:
+            vals['internal'] = itemp
+
+        self.server.add_reading(vals)
+
     def _run(self):
         while True:
             self.do()
@@ -52,14 +65,13 @@
             EX("Problem reading sensor '%s': %s" % (s, str(e)))
             return None
 
-    def do(self):
-        vals = {}
-        for n in self.sensor_names():
-                value = self.do_sensor(n)
-                if value is not None:
-                    vals[n] = value
-
-        self.server.add_reading(vals)
+    def do_internal(self):
+        try:
+            return int(open(config.INTERNAL_TEMPERATURE, 'r').read()) / 1000.0
+        except Exception, e:
+            EX("Problem reading internal sensor: %s" % str(e))
+            return None
+        
 
     def sensor_names(self):
         """ Returns a sequence of sensorname """