comparison py/uploader.py @ 253:0a1b642e3086

long polling config updates
author Matt Johnston <matt@ucc.asn.au>
date Mon, 08 Jun 2015 22:29:46 +0800
parents 86e638d564b0
children 6d06795aefbb
comparison
equal deleted inserted replaced
251:b6079cb0c665 253:0a1b642e3086
34 34
35 tosend['wort_name'] = self.server.wort_name 35 tosend['wort_name'] = self.server.wort_name
36 tosend['fridge_name'] = self.server.wort_name 36 tosend['fridge_name'] = self.server.wort_name
37 37
38 tosend['current_params'] = dict(self.server.params) 38 tosend['current_params'] = dict(self.server.params)
39 tosend['current_params_epoch'] = self.server.params.get_epoch()
39 40
40 tosend['start_time'] = self.server.start_time 41 tosend['start_time'] = self.server.start_time
41 tosend['uptime'] = utils.uptime() 42 tosend['uptime'] = utils.uptime()
42 43
43 return tosend 44 return tosend
51 js_enc = binascii.b2a_base64(zlib.compress(js.encode())).strip() 52 js_enc = binascii.b2a_base64(zlib.compress(js.encode())).strip()
52 mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha256).hexdigest() 53 mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha256).hexdigest()
53 send_data = {'data': js_enc.decode(), 'hmac': mac} 54 send_data = {'data': js_enc.decode(), 'hmac': mac}
54 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60) 55 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60)
55 result = yield from asyncio.wait_for(r.text(), 60) 56 result = yield from asyncio.wait_for(r.text(), 60)
56 if result != 'OK': 57 if r.status == 200 and result != 'OK':
57 raise Exception("Server returned %s" % result) 58 raise Exception("Server returned %s" % result)
58 59
59 @asyncio.coroutine 60 @asyncio.coroutine
60 def do(self): 61 def do(self):
61 readings = self.server.take_readings() 62 readings = self.server.take_readings()