changeset 368:d4c9c360448f

merge
author Matt Johnston <matt@ucc.asn.au>
date Tue, 26 Jun 2012 21:21:09 +0800
parents daad73f65c0f (current diff) 3db118498b97 (diff)
children aaa94f90eaa1
files main.c
diffstat 4 files changed, 49 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Tue Jun 26 00:00:42 2012 +0800
+++ b/main.c	Tue Jun 26 21:21:09 2012 +0800
@@ -625,10 +625,7 @@
 {
     PRR &= ~_BV(PRADC);
     
-    // left adjust
-    ADMUX = _BV(ADLAR);
-
-    // /128 prescaler
+    // /16 prescaler
     ADCSRA = _BV(ADEN) | _BV(ADPS2);
 
     // set to measure 1.1 reference
--- a/web/config.py	Tue Jun 26 00:00:42 2012 +0800
+++ b/web/config.py	Tue Jun 26 21:21:09 2012 +0800
@@ -11,8 +11,14 @@
 LINE_WIDTH = 2
 
 SENSOR_NAMES = {'sensor_28 CE B2 1A 03 00 00 99': "Wort",
-    'sensor_28 CC C1 1A 03 00 00 D4': "Board"}
+    'sensor_28 CC C1 1A 03 00 00 D4': "Board",
+    'sensor_voltage': 'Voltage',
+    }
 
-SENSOR_COLOURS = {'Wort': 'e49222', 'Board': '028b3d'}
+SENSOR_COLOURS = {'Wort': 'e49222', 
+                'Board': '028b3d',
+                'Voltage': '7db5d3aa',
+                }
+
 
 GRAPH_FONT = "Courier"
--- a/web/log.py	Tue Jun 26 00:00:42 2012 +0800
+++ b/web/log.py	Tue Jun 26 21:21:09 2012 +0800
@@ -25,13 +25,17 @@
 def create_rrd(sensor_id):
     # start date of 10 seconds into 1970 is used so that we can
     # update with prior values straight away.
-    args = [sensor_rrd_path(sensor_id), 
-                    '--start', '10',
-                    '--step', '300',
-                    'DS:temp:GAUGE:600:-10:100',
-                    'RRA:AVERAGE:0.5:1:1051200']
+    if 'voltage' in sensor_id:
+        args = [ 'DS:temp:GAUGE:7200:-1:10',
+                'RRA:AVERAGE:0.9999:1:1051200']
+    else:
+        args = [ 'DS:temp:GAUGE:600:-10:100',
+                'RRA:AVERAGE:0.5:1:1051200']
 
-    rrdtool.create(*args)
+    rrdtool.create(sensor_rrd_path(sensor_id), 
+                '--start', '10',
+                '--step', '300',
+                *args)
 
 # stolen from viewmtn, stolen from monotone-viz
 def colour_from_string(str):
@@ -47,9 +51,18 @@
     rrds = all_sensors()
 
     graph_args = []
+    have_volts = False
     for n, (rrdfile, sensor) in enumerate(rrds):
-        vname = 'temp%d' % n
-        graph_args.append('DEF:%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals())
+        if 'avrtemp' in sensor:
+            continue
+        if 'voltage' in sensor:
+            have_volts = True
+            vname = 'scalevolts'
+            graph_args = ['DEF:rawvolts=%(rrdfile)s:temp:AVERAGE:step=3600' % locals(),
+                        'CDEF:scalevolts=rawvolts,0.2,/'] + graph_args
+        else:
+            vname = 'temp%d' % n
+            graph_args.append('DEF:%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals())
         width = config.LINE_WIDTH
         legend = config.SENSOR_NAMES.get(sensor, sensor)
         colour = config.SENSOR_COLOURS.get(legend, colour_from_string(sensor))
@@ -62,16 +75,22 @@
         '-h', str(config.GRAPH_HEIGHT),
         '--slope-mode',
         '--border', '0',
+        '--vertical-label', 'Temperature',
         '--y-grid', '1:1',
         '--grid-dash', '1:0',
         '--color', 'GRID#00000000',
         '--color', 'MGRID#aaaaaa',
         '--color', 'BACK#ffffff',
+        'VRULE:%d#ee0000' % time.time(),
         '--imgformat', 'PNG'] \
         + graph_args
     if config.GRAPH_FONT:
         args += ['--font', 'DEFAULT:11:%s' % config.GRAPH_FONT]
-    print>>sys.stderr, args
+    if have_volts:
+        args += ['--right-axis', '0.2:0', # matches the scalevolts CDEF above
+            '--right-axis-format', '%.2lf',
+            '--right-axis-label', 'Voltage']
+
     rrdtool.graph(*args)
     return tempf.read()
 
@@ -81,15 +100,12 @@
     except IOError, e:
         create_rrd(sensor_id)
 
-    print>>sys.stderr, sensor_id, measurements, first_real_time, time_step
-
     if measurements:
         values = ['%d:%f' % p for p in 
             zip((first_real_time + time_step*t for t in xrange(len(measurements))),
                 measurements)]
 
         rrdfile = sensor_rrd_path(sensor_id)
-        print>>sys.stderr, values
         # XXX what to do here when it fails...
         for v in values:
             try:
@@ -142,6 +158,14 @@
     avr_first_time = float(entries['first_time'])
     time_step = float(entries['time_step'])
 
+    if 'avrtemp' in entries:
+        avrtemp = val_scale(int(entries['avrtemp']))
+        sensor_update('avrtemp', [avrtemp], time.time(), 1)
+
+    if 'voltage' in entries:
+        voltage = 0.001 * int(entries['voltage'])
+        sensor_update('voltage', [voltage], time.time(), 1)
+
     #sqlite 
     # - time
     # - voltage
--- a/web/templog.py	Tue Jun 26 00:00:42 2012 +0800
+++ b/web/templog.py	Tue Jun 26 21:21:09 2012 +0800
@@ -40,7 +40,7 @@
             start_hour = datetime.datetime.now() - datetime.timedelta(days=1)
 
         start = time.mktime(start_hour.timetuple())
-        length = int(request.query.get('length', 36)) * 3600
+        length = int(request.query.get('length', 26)) * 3600
 
     response.set_header('Content-Type', 'image/png')
     return log.graph_png(start, length)
@@ -61,8 +61,9 @@
     return 'done'
 
 def main():
-    bottle.debug(True)
-    bottle.run(server='cgi')
+    #bottle.debug(True)
+    #bottle.run(reloader=True)
+    bottle.run(server='cgi', reloader=True)
     #bottle.run(port=9999, reloader=True)
 
 if __name__ == '__main__':