# HG changeset patch # User Matt Johnston # Date 1340460623 -28800 # Node ID d6219df77c41b3b3f113a3aab822be7203508179 # Parent a3473b5ea50e5bedcfad59f14b43363e36ef7d9e 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 diff -r a3473b5ea50e -r d6219df77c41 main.c --- 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: - * Copyright: - * License: - */ - #include #include #include @@ -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 */ diff -r a3473b5ea50e -r d6219df77c41 server/ts.py --- 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 diff -r a3473b5ea50e -r d6219df77c41 web/log.py --- 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)) diff -r a3473b5ea50e -r d6219df77c41 web/templog.py --- a/web/templog.py Sat Jun 16 09:08:47 2012 +0800 +++ b/web/templog.py Sat Jun 23 22:10:23 2012 +0800 @@ -58,7 +58,8 @@ def main(): bottle.debug(True) - bottle.run(port=9999, reloader=True) + bottle.run(server='cgi') + #bottle.run(port=9999, reloader=True) if __name__ == '__main__': main()