changeset 242:2caee09f41c4

merge from server
author Matt Johnston <matt@ucc.asn.au>
date Wed, 20 May 2015 00:03:53 +0800
parents 86e638d564b0 (diff) c90190a380c6 (current diff)
children c9b20d3d393a
files
diffstat 3 files changed, 13 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/py/sensor_ds18b20.py	Tue May 19 23:56:56 2015 +0800
+++ b/py/sensor_ds18b20.py	Wed May 20 00:03:53 2015 +0800
@@ -8,7 +8,7 @@
 import config
 from utils import D,L,W,E,EX
 
-class DS18B20s(object):
+class SensorDS18B20(object):
 
     THERM_RE = re.compile('.* YES\n.*t=(.*)\n', re.MULTILINE)
 
@@ -37,6 +37,7 @@
             yield from self.do()
             yield from self.server.sleep(config.SENSOR_SLEEP)
 
+
     @asyncio.coroutine
     def read_wait(self, f):
         # handles a blocking file read with a threadpool. A
@@ -45,7 +46,7 @@
         # the ds18b20 takes ~750ms to read, which is noticable
         # interactively.
         loop = asyncio.get_event_loop()
-        yield from loop.run_in_executor(self.readthread, f.read)
+        return loop.run_in_executor(None, f.read)
 
     @asyncio.coroutine
     def do_sensor(self, s, contents = None):
@@ -53,8 +54,8 @@
         try:
             if contents is None:
                 fn = os.path.join(self.master_dir, s, 'w1_slave')
-                f = open(fn, 'r')
-                contents = yield from self.read_wait(f)
+                with open(fn, 'r') as f:
+                    contents = yield from self.read_wait(f)
 
             match = self.THERM_RE.match(contents)
             if match is None:
@@ -71,7 +72,8 @@
 
     def do_internal(self):
         try:
-            return int(open(config.INTERNAL_TEMPERATURE, 'r').read()) / 1000.0
+            with open(config.INTERNAL_TEMPERATURE, 'r') as f:
+                return int(f.read()) / 1000.0
         except Exception as e:
             EX("Problem reading internal sensor: %s" % str(e))
             return None
@@ -80,7 +82,8 @@
     def sensor_names(self):
         """ Returns a sequence of sensorname """
         slaves_path = os.path.join(self.master_dir, "w1_master_slaves")
-        contents = open(slaves_path, 'r').read()
+        with open(slaves_path, 'r') as f:
+            contents = f.read()
         if 'not found' in contents:
             E("No W1 sensors found")
             return []
--- a/py/setup_gpio.sh	Tue May 19 23:56:56 2015 +0800
+++ b/py/setup_gpio.sh	Wed May 20 00:03:53 2015 +0800
@@ -2,15 +2,8 @@
 
 # this must run as root
 
-PINS="17 7 24 25"
-GROUP=fridgeio
+PINS="17"
 
 for PIN in $PINS; do
     echo $PIN > /sys/class/gpio/export
-
-    for f in direction value; do
-        fn=/sys/devices/virtual/gpio/gpio$PIN/$f
-        chgrp $GROUP $fn
-        chmod g+rw $fn
-    done
 done
--- a/py/uploader.py	Tue May 19 23:56:56 2015 +0800
+++ b/py/uploader.py	Wed May 20 00:03:53 2015 +0800
@@ -48,9 +48,9 @@
         if self.server.test_mode():
             D("Would upload %s to %s" % (js, config.UPDATE_URL))
             return
-        js_enc = binascii.b2a_base64(zlib.compress(js.encode()))
-        mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha1).hexdigest()
-        send_data = {'data': js_enc, 'hmac': mac}
+        js_enc = binascii.b2a_base64(zlib.compress(js.encode())).strip()
+        mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha256).hexdigest()
+        send_data = {'data': js_enc.decode(), 'hmac': mac}
         r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60)
         result = yield from asyncio.wait_for(r.text(), 60)
         if result != 'OK':