Mercurial > templog
comparison 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 |
comparison
equal
deleted
inserted
replaced
149:d686b111dab4 | 151:e114b38c8a55 |
---|---|
16 def __init__(self, server): | 16 def __init__(self, server): |
17 gevent.Greenlet.__init__(self) | 17 gevent.Greenlet.__init__(self) |
18 self.server = server | 18 self.server = server |
19 self.readthread = gevent.threadpool.ThreadPool(1) | 19 self.readthread = gevent.threadpool.ThreadPool(1) |
20 self.master_dir = config.SENSOR_BASE_DIR | 20 self.master_dir = config.SENSOR_BASE_DIR |
21 | |
22 def do(self): | |
23 vals = {} | |
24 for n in self.sensor_names(): | |
25 value = self.do_sensor(n) | |
26 if value is not None: | |
27 vals[n] = value | |
28 | |
29 itemp = self.do_internal() | |
30 if itemp: | |
31 vals['internal'] = itemp | |
32 | |
33 self.server.add_reading(vals) | |
21 | 34 |
22 def _run(self): | 35 def _run(self): |
23 while True: | 36 while True: |
24 self.do() | 37 self.do() |
25 gevent.sleep(config.SENSOR_SLEEP) | 38 gevent.sleep(config.SENSOR_SLEEP) |
50 return temp | 63 return temp |
51 except Exception, e: | 64 except Exception, e: |
52 EX("Problem reading sensor '%s': %s" % (s, str(e))) | 65 EX("Problem reading sensor '%s': %s" % (s, str(e))) |
53 return None | 66 return None |
54 | 67 |
55 def do(self): | 68 def do_internal(self): |
56 vals = {} | 69 try: |
57 for n in self.sensor_names(): | 70 return int(open(config.INTERNAL_TEMPERATURE, 'r').read()) / 1000.0 |
58 value = self.do_sensor(n) | 71 except Exception, e: |
59 if value is not None: | 72 EX("Problem reading internal sensor: %s" % str(e)) |
60 vals[n] = value | 73 return None |
61 | 74 |
62 self.server.add_reading(vals) | |
63 | 75 |
64 def sensor_names(self): | 76 def sensor_names(self): |
65 """ Returns a sequence of sensorname """ | 77 """ Returns a sequence of sensorname """ |
66 slaves_path = os.path.join(self.master_dir, "w1_master_slaves") | 78 slaves_path = os.path.join(self.master_dir, "w1_master_slaves") |
67 names = open(slaves_path, 'r').read().split() | 79 names = open(slaves_path, 'r').read().split() |