comparison web/log.py @ 75:ca08442635ca

report raw ds18b20 values instead
author Matt Johnston <matt@ucc.asn.au>
date Tue, 03 Jul 2012 22:44:21 +0800
parents 0a8639039453
children 959e88c0bdfa
comparison
equal deleted inserted replaced
74:cb5ea75ee599 75:ca08442635ca
9 import time 9 import time
10 import syslog 10 import syslog
11 import sqlite3 11 import sqlite3
12 import traceback 12 import traceback
13 import datetime 13 import datetime
14 import struct
14 from colorsys import hls_to_rgb 15 from colorsys import hls_to_rgb
15 16
16 import config 17 import config
17 18
18 def sensor_rrd_path(s): 19 def sensor_rrd_path(s):
141 f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S')) 142 f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S'))
142 f.writelines(('%s\n' % s for s in lines)) 143 f.writelines(('%s\n' % s for s in lines))
143 f.flush() 144 f.flush()
144 return f 145 return f
145 146
147 def convert_ds18b20_12bit(reading):
148 value = struct.unpack('>h', binascii.unhexlify(reading))[0]
149 return value * 0.0625
150
146 def parse(lines): 151 def parse(lines):
147 152
148 debugf = record_debug(lines) 153 debugf = record_debug(lines)
149 154
150 entries = dict(l.split('=', 1) for l in lines) 155 entries = dict(l.split('=', 1) for l in lines)
157 sensors = [entries['sensor_id%d' % n] for n in xrange(num_sensors)] 162 sensors = [entries['sensor_id%d' % n] for n in xrange(num_sensors)]
158 163
159 meas = [] 164 meas = []
160 for s in sensors: 165 for s in sensors:
161 meas.append([]) 166 meas.append([])
162
163 def val_scale(v):
164 # convert decidegrees to degrees
165 return 0.1 * v
166 167
167 for n in xrange(num_measurements): 168 for n in xrange(num_measurements):
168 vals = [val_scale(int(x)) for x in entries["meas%d" % n].strip().split()] 169 vals = [val_scale(int(x)) for x in entries["meas%d" % n].strip().split()]
169 if len(vals) != num_sensors: 170 if len(vals) != num_sensors:
170 raise Exception("Wrong number of sensors for measurement %d" % n) 171 raise Exception("Wrong number of sensors for measurement %d" % n)