Mercurial > templog
changeset 40:9b5b202129c3
main.c:
- get rid of some debugging
- separate uart_enabled flag
ts.py:
- remember next wake time, not the interval
log.py:
- comments for sqlite
templog.py
- use cgi
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 23 Jun 2012 22:10:23 +0800 |
parents | 9a3b967a920c |
children | 1701457e6007 ea99aae87884 |
files | main.c server/ts.py web/log.py web/templog.py |
diffstat | 4 files changed, 22 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Sat Jun 16 09:08:47 2012 +0800 +++ b/main.c Sat Jun 23 22:10:23 2012 +0800 @@ -1,9 +1,3 @@ -/* Name: main.c - * Author: <insert your name here> - * Copyright: <insert your copyright message here> - * License: <insert your license reference here> - */ - #include <stdio.h> #include <string.h> #include <stddef.h> @@ -85,6 +79,7 @@ // boolean flags static uint8_t need_measurement; static uint8_t need_comms; +static uint8_t uart_enabled; // counts down from WAKE_SECS to 0, goes to deep sleep when hits 0 static uint8_t comms_timeout; @@ -184,23 +179,27 @@ UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); //8N1 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); + uart_enabled = 1; } static void uart_off() { -#if 0 // Turn of interrupts and disable tx/rx UCSR0B = 0; + uart_enabled = 0; // Power reduction register //PRR |= _BV(PRUSART0); -#endif } int uart_putchar(char c, FILE *stream) { + if (!uart_enabled) + { + return EOF; + } // XXX could perhaps sleep in the loop for power. if (c == '\n') { @@ -222,7 +221,7 @@ crc_out = _crc_ccitt_update(crc_out, '\n'); } } - return 0; + return (unsigned char)c; } static void @@ -753,13 +752,6 @@ need_comms = 1; need_measurement = 1; -#if 0 - for (;;) - { - do_comms(); - } -#endif - for(;;) { if (need_measurement) @@ -778,7 +770,6 @@ deep_sleep(); blink(); - printf("."); } return 0; /* never reached */
--- a/server/ts.py Sat Jun 16 09:08:47 2012 +0800 +++ b/server/ts.py Sat Jun 23 22:10:23 2012 +0800 @@ -167,6 +167,7 @@ time.sleep(length) def main(): + next_wake_time = 0 while True: sock = None @@ -179,12 +180,13 @@ if sock: next_wake = None try: - next_wake = do_comms(sock) + next_wake_interval = do_comms(sock) + next_wake_time = time.now() + next_wake_interval except Exception, e: print>>sys.stderr, "Error in do_comms:" traceback.print_exc(file=sys.stderr) - if next_wake: - sleep_time = min(next_wake+EXTRA_WAKEUP, sleep_time) + if next_wake_time > time.now(): + sleep_time = min(next_wake_time - time.now() - EXTRA_WAKEUP, sleep_time) if TESTING: print "Sleeping for %d" % sleep_time
--- a/web/log.py Sat Jun 16 09:08:47 2012 +0800 +++ b/web/log.py Sat Jun 23 22:10:23 2012 +0800 @@ -79,6 +79,7 @@ rrdfile = sensor_rrd_path(sensor_id) print>>sys.stderr, values + # XXX what to do here when it fails... rrdtool.update(rrdfile, *values) # be paranoid @@ -125,9 +126,15 @@ avr_first_time = float(entries['first_time']) time_step = float(entries['time_step']) + #sqlite + # - time + # - voltage + # - boot time + first_real_time = time.time() - (avr_now - avr_first_time) for sensor_id, measurements in zip(sensors, meas): + # XXX sqlite add sensor_update(sensor_id, measurements, first_real_time, time_step) debugf.write("Updated %d sensors\n" % len(sensors))