diff py/uploader.py @ 160:256505f98c4d

uploader works
author Matt Johnston <matt@ucc.asn.au>
date Thu, 03 Jan 2013 22:37:33 +0800
parents 3b4277aaed3c
children bf2a17873ba1
line wrap: on
line diff
--- a/py/uploader.py	Thu Jan 03 22:35:54 2013 +0800
+++ b/py/uploader.py	Thu Jan 03 22:37:33 2013 +0800
@@ -1,8 +1,15 @@
-import config
-
 import json
 import hmac
 import zlib
+import binascii
+import urllib
+import urllib2
+
+import gevent
+
+import config
+from utils import L,D,EX,W,E
+import utils
 
 class Uploader(gevent.Greenlet):
     def __init__(self, server):
@@ -10,6 +17,7 @@
         self.server = server
 
     def _run(self):
+        gevent.sleep(5)
         while True:
             self.do()
             gevent.sleep(config.UPLOAD_SLEEP)
@@ -23,7 +31,7 @@
         tosend['readings'] = readings
 
         tosend['wort_name'] = self.server.wort_name
-        tosend['fridge_name'] = self.server.wort_fridge_name
+        tosend['fridge_name'] = self.server.wort_name
 
         tosend.update(dict(self.server.params))
 
@@ -42,14 +50,18 @@
         if result != 'OK':
             raise Exception("Server returned %s" % result)
 
-    def do():
+    def do(self):
         readings = self.server.take_readings()
         try:
             tosend = self.get_tosend(readings)
-            readings = None
+            nreadings = len(readings)
             self.send(tosend)
+            readings = None
+            L("Sent updated %d readings" % nreadings)
+        except urllib2.HTTPError, e:
+            E("Error in uploader: %s" % str(e))
         except Exception, e:
-            EX"Error in uploader: %s" % str(e))
+            EX("Error in uploader: %s" % str(e))
         finally:
             if readings is not None:
                 self.server.pushfront(readings)