Mercurial > templog
changeset 151:e114b38c8a55
internal temperature sensor
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 20 Dec 2012 22:24:42 +0800 |
parents | d686b111dab4 |
children | 102e6602bb2d |
files | py/config.py py/sensor_ds18b20.py |
diffstat | 2 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/py/config.py Sun Dec 16 22:14:46 2012 +0800 +++ b/py/config.py Thu Dec 20 22:24:42 2012 +0800 @@ -12,3 +12,4 @@ FRIDGE_GPIO = '/sys/devices/virtual/gpio/gpio17' WORT_NAME = '28-0000031abc49' FRIDGE_NAME = 'bb' +INTERNAL_TEMPERATURE = '/sys/class/thermal/thermal_zone0/temp'
--- 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 """