changeset 102:68a44d0ec599

merge
author Matt Johnston <matt@ucc.asn.au>
date Wed, 25 Jul 2012 23:03:34 +0800
parents 9485da05bc11 (diff) fd8482365489 (current diff)
children ef59da811986
files
diffstat 3 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Wed Jul 25 23:03:10 2012 +0800
+++ b/main.c	Wed Jul 25 23:03:34 2012 +0800
@@ -67,7 +67,7 @@
 
 // eeprom-settable parameters. all timeouts should
 // be a multiple of TICK (6 seconds probably)
-static uint16_t measure_wake = 120;
+static uint16_t measure_wake = 138; // not a divisor of comms_wake
 static uint16_t comms_wake = 3600;
 static uint8_t wake_secs = 30;
 
@@ -797,12 +797,6 @@
             need_comms = 1;
             comms_timeout = wake_secs;
             button_pressed = 0;
-        }
-
-        if (need_measurement)
-        {
-            need_measurement = 0;
-            do_measurement();
             continue;
         }
 
@@ -813,6 +807,13 @@
             continue;
         }
 
+        if (need_measurement)
+        {
+            need_measurement = 0;
+            do_measurement();
+            continue;
+        }
+
         deep_sleep();
     }
 
--- a/server/ts.py	Wed Jul 25 23:03:10 2012 +0800
+++ b/server/ts.py	Wed Jul 25 23:03:34 2012 +0800
@@ -1,7 +1,7 @@
 #!/usr/bin/env python2.7
 
 # time that the bluetooth takes to get going?
-EXTRA_WAKEUP = 0
+EXTRA_WAKEUP = -3
 
 FETCH_TRIES = 3
 
@@ -34,8 +34,10 @@
 
 def get_socket(addr):
     s = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
+    L("connecting")
     s.connect((addr, 1))
     s.setblocking(False)
+    s.settimeout(1)
             
     return s
 
@@ -49,7 +51,7 @@
     lines = []
     l = readline(sock)
     if l != 'START\n':
-        W("Bad expected START line '%s'\n" % l.rstrip('\n'))
+        W("Bad expected START line '%s'\n" % str(l).rstrip('\n'))
         return None
     crc = crc16(l, crc)
 
@@ -181,6 +183,7 @@
     if '--daemon' in sys.argv:
         utils.cheap_daemon()
 
+    next_wake_time = 0
     while True:
         sock = None
         try:
@@ -188,7 +191,6 @@
         except Exception, e:
             #logging.exception("Error connecting")
             pass
-        next_wake_time = 0
         if sock:
             try:
                 avr_wake = do_comms(sock)
@@ -196,11 +198,14 @@
             except Exception, e:
                 logging.exception("Error in do_comms")
 
-        next_wake_interval = next_wake_time - time.time() - EXTRA_WAKEUP
+        next_wake_interval = next_wake_time - time.time() + EXTRA_WAKEUP
         sleep_time = config.SLEEP_TIME
         if next_wake_interval > 0:
             sleep_time = min(next_wake_interval, sleep_time)
-        L("Sleeping for %d, next wake time %f" % (sleep_time, next_wake_time))
+        if next_wake_interval < 0 and next_wake_interval > -30:
+            L("not sleeping, next_wake_interval overdue %f" % next_wake_interval)
+            continue
+        L("Sleeping for %d, next wake interval %f" % (sleep_time, next_wake_interval))
         sleep_for(sleep_time)
 
 if __name__ == '__main__':
--- a/web/config.py	Wed Jul 25 23:03:10 2012 +0800
+++ b/web/config.py	Wed Jul 25 23:03:34 2012 +0800
@@ -1,4 +1,3 @@
-
 # for server
 BTADDR = "00:12:03:27:70:88"
 SLEEP_TIME = 5