# HG changeset patch # User Matt Johnston # Date 1418999579 -28800 # Node ID 838e868a046e869959f20592274e6cfb9e3fcd26 # Parent 0b5ff341d12416cdac1a3b9e379dae4b245bd63b make the fridge off timer more robust add a few comments diff -r 0b5ff341d124 -r 838e868a046e py/config.py --- a/py/config.py Fri Dec 19 21:52:50 2014 +0800 +++ b/py/config.py Fri Dec 19 22:32:59 2014 +0800 @@ -1,13 +1,13 @@ import os.path -FRIDGE_SLEEP = 60 -SENSOR_SLEEP = 15 -UPLOAD_SLEEP = 80 +FRIDGE_SLEEP = 60 # this value works. may affect the algorithm +SENSOR_SLEEP = 15 # same for this. +UPLOAD_SLEEP = 83 # nice and prime -FRIDGE_DELAY = 600 # 10 mins +FRIDGE_DELAY = 600 # 10 mins, to avoid fridge damage from frequent cycling off/on FRIDGE_WORT_INVALID_TIME = 300 # 5 mins -# 12 hours +# 12 hours of "offline" readings stored MAX_READINGS = 12*60*60 / SENSOR_SLEEP PARAMS_FILE = os.path.join(os.path.dirname(__file__), 'tempserver.conf') @@ -23,6 +23,7 @@ #UPDATE_URL = 'https://matt.ucc.asn.au/test/templog/update' UPDATE_URL = 'https://evil.ucc.asn.au/~matt/templog/update' +# site-local values overridden in localconfig, eg WORT_NAME, HMAC_KEY try: from localconfig import * except ImportError: diff -r 0b5ff341d124 -r 838e868a046e py/fridge.py --- a/py/fridge.py Fri Dec 19 21:52:50 2014 +0800 +++ b/py/fridge.py Fri Dec 19 22:32:59 2014 +0800 @@ -13,13 +13,14 @@ self.setup_gpio() self.wort_valid_clock = 0 self.fridge_on_clock = 0 - self.fridge_off_clock = server.now() + self.off() def setup_gpio(self): dir_fn = '%s/direction' % config.FRIDGE_GPIO with open(dir_fn, 'w') as f: f.write('low') val_fn = '%s/value' % config.FRIDGE_GPIO + # XXX - Fridge should have __enter__/__exit__, close the file there. self.value_file = open(val_fn, 'r+') def turn(self, value): @@ -35,6 +36,7 @@ def off(self): self.turn(False) + self.fridge_off_clock = self.server.now() def is_on(self): self.value_file.seek(0) @@ -71,7 +73,9 @@ if wort is not None: self.wort_valid_clock = self.server.now() - if off_time < config.FRIDGE_DELAY: + # Safety to avoid bad things happening to the fridge motor (?) + # When it turns off don't start up again for at least FRIDGE_DELAY + if self.is_off() and off_time < config.FRIDGE_DELAY: L("fridge skipping, too early") return @@ -116,7 +120,6 @@ if turn_off: L("Turning fridge off") self.off() - self.fridge_off_clock = self.server.now() else: # fridge is off