changeset 345:a3473b5ea50e

merge
author Matt Johnston <matt@ucc.asn.au>
date Sat, 16 Jun 2012 09:08:47 +0800
parents aa247177837a (diff) ea1779d27641 (current diff)
children d6219df77c41
files web/index.py
diffstat 2 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sat Jun 16 09:08:07 2012 +0800
+++ b/main.c	Sat Jun 16 09:08:47 2012 +0800
@@ -30,7 +30,7 @@
 // 1 second. we have 1024 prescaler, 32768 crystal.
 #define SLEEP_COMPARE 32
 // limited to uint16_t
-#define MEASURE_WAKE 300
+#define MEASURE_WAKE 20
 
 #define VALUE_NOSENSOR -9000
 #define VALUE_BROKEN -8000
@@ -234,11 +234,11 @@
 
     fprintf_P(crc_stdout, PSTR("START\n"));
     fprintf_P(crc_stdout, PSTR("now=%lu\n"
-                                "time_step=%lu\n"
+                                "time_step=%hu\n"
                                 "first_time=%lu\n"
                                 "last_time=%lu\n"), 
                                 clock_epoch, 
-                                MEASURE_WAKE, 
+                                (uint16_t)MEASURE_WAKE, 
                                 first_measurement_clock, 
                                 last_measurement_clock);
     fprintf_P(crc_stdout, PSTR("sensors=%u\n"), n_sensors);
@@ -250,13 +250,13 @@
         printhex(id, ID_LEN, crc_stdout);
         fputc('\n', crc_stdout);
     }
-    fprintf_P(crc_stdout, PSTR("measurements=%u\n"), n_measurements);
+    fprintf_P(crc_stdout, PSTR("measurements=%hu\n"), n_measurements);
     for (uint16_t n = 0; n < n_measurements; n++)
     {
         fprintf_P(crc_stdout, PSTR("meas%u="), n);
         for (uint8_t s = 0; s < n_sensors; s++)
         {
-            fprintf_P(crc_stdout, PSTR(" %u"), measurements[n][s]);
+            fprintf_P(crc_stdout, PSTR(" %hu"), measurements[n][s]);
         }
         fputc('\n', crc_stdout);
     }
@@ -519,7 +519,8 @@
 
     if (comms_timeout != 0)
     {
-        comms_timeout--;
+        // XXX testing
+        //comms_timeout--;
     }
 
     if (measure_count >= MEASURE_WAKE)
@@ -750,6 +751,7 @@
     sei();
 
     need_comms = 1;
+    need_measurement = 1;
 
 #if 0
     for (;;)
--- a/server/ts.py	Sat Jun 16 09:08:07 2012 +0800
+++ b/server/ts.py	Sat Jun 16 09:08:47 2012 +0800
@@ -19,6 +19,8 @@
 import binascii
 import hmac
 import zlib
+import urllib
+import urllib2
 
 import config
 
@@ -57,7 +59,6 @@
         print>>sys.stderr, "Bad expected START line '%s'\n" % l.rstrip('\n')
         return None
     crc = crc16(l, crc)
-    lines.append(l)
 
     while True:
         l = readline(sock)
@@ -122,9 +123,9 @@
 
 def send_results(lines):
     enc_lines = binascii.b2a_base64(zlib.compress('\n'.join(lines)))
-    hmac.new(config.HMAC_KEY, enc_lines).hexdigest()
+    mac = hmac.new(config.HMAC_KEY, enc_lines).hexdigest()
 
-    url_data = urllib.url_encode( ('lines', enc_lines), ('hmac', mac) )
+    url_data = urllib.urlencode( {'lines': enc_lines, 'hmac': mac} )
     con = urllib2.urlopen(config.UPDATE_URL, url_data)
     result = con.read(100)
     if result == 'OK':