Mercurial > templog
changeset 180:15ebb9de5049
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 30 Jan 2014 22:56:17 +0800 |
parents | 77c2a9caca3d (diff) 30390852cb5d (current diff) |
children | 1731a27bcdd2 e731c0d30b09 f4aabbf0da67 |
files | |
diffstat | 7 files changed, 60 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/py/config.py Thu Jan 30 22:56:05 2014 +0800 +++ b/py/config.py Thu Jan 30 22:56:17 2014 +0800 @@ -20,7 +20,8 @@ INTERNAL_TEMPERATURE = '/sys/class/thermal/thermal_zone0/temp' HMAC_KEY = "a key" -UPDATE_URL = 'https://matt.ucc.asn.au/test/templog/update' +#UPDATE_URL = 'https://matt.ucc.asn.au/test/templog/update' +UPDATE_URL = 'https://evil.ucc.asn.au/~matt/templog/update' try: from localconfig import *
--- a/py/fridge.py Thu Jan 30 22:56:05 2014 +0800 +++ b/py/fridge.py Thu Jan 30 22:56:17 2014 +0800 @@ -6,8 +6,6 @@ class Fridge(gevent.Greenlet): OVERSHOOT_MAX_DIV = 1800.0 # 30 mins - FRIDGE_AIR_MIN_RANGE = 4 # ºC - FRIDGE_AIR_MAX_RANGE = 4 def __init__(self, server): gevent.Greenlet.__init__(self) @@ -62,13 +60,17 @@ params = self.server.params - fridge_min = params.fridge_setpoint - self.FRIDGE_AIR_MIN_RANGE - fridge_max = params.fridge_setpoint + self.FRIDGE_AIR_MAX_RANGE + fridge_min = params.fridge_setpoint - params.fridge_range_lower + fridge_max = params.fridge_setpoint + params.fridge_range_upper + wort_min = params.fridge_setpoint wort_max = params.fridge_setpoint + params.fridge_difference off_time = self.server.now() - self.fridge_off_clock + if wort is not None: + self.wort_valid_clock = self.server.now() + if off_time < config.FRIDGE_DELAY: L("fridge skipping, too early") return @@ -80,9 +82,8 @@ return # handle broken wort sensor - if wort is not None: + if wort is None: self.wort_valid_clock = self.server.now() - else: W("Invalid wort sensor") invalid_time = self.server.now() - self.wort_valid_clock if invalid_time < config.FRIDGE_WORT_INVALID_TIME: @@ -103,14 +104,14 @@ / self.OVERSHOOT_MAX_DIV D("on_time %(on_time)f, overshoot %(overshoot)f" % locals()) - if wort is not None: - if (wort - overshoot) < params.fridge_setpoint: - L("wort has cooled enough") + if not params.nowort and wort is not None: + if wort - overshoot < params.fridge_setpoint: + L("wort has cooled enough, %(wort)f" % locals() ) turn_off = True - else: - # wort sensor is broken - if fridge is not None and fridge < fridge_min: - W("fridge off fallback") + elif fridge is not None and fridge < fridge_min: + W("fridge off fallback, fridge %(fridge)f, min %(fridge_min)f" % locals()) + if wort is None: + W("wort has been invalid for %d" % (self.server.now() - self.wort_valid_clock)) turn_off = True if turn_off: @@ -121,14 +122,13 @@ else: # fridge is off turn_on = False - if wort is not None: - if wort >= wort_max: + if not params.nowort \ + and wort is not None \ + and wort >= wort_max: L("Wort is too hot %f, max %f" % (wort, wort_max)) turn_on = True - else: - # wort sensor is broken - if fridge is not None and fridge >= fridge_max: - W("frdge on fallback") + elif fridge is not None and fridge >= fridge_max: + W("frdge on fallback, fridge %(fridge)f, max %(fridge_max)f" % locals()) turn_on = True if turn_on:
--- a/py/params.py Thu Jan 30 22:56:05 2014 +0800 +++ b/py/params.py Thu Jan 30 22:56:17 2014 +0800 @@ -15,6 +15,9 @@ 'overshoot_delay': 720, # 12 minutes 'overshoot_factor': 1, # ºC 'disabled': False, + 'nowort': False, + 'fridge_range_lower': 3, + 'fridge_range_upper': 3, } class Params(dict): @@ -46,6 +49,8 @@ raise self.Error(e) for k in u: + if k.startswith('_'): + continue if k not in self: raise self.Error("Unknown parameter %s=%s in file '%s'" % (str(k), str(u[k]), getattr(f, 'name', '???'))) self.update(u)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/py/requirements.txt Thu Jan 30 22:56:17 2014 +0800 @@ -0,0 +1,7 @@ +argparse==1.2.1 +gevent==1.0rc2 +greenlet==0.4.0 +lockfile==0.9.1 +python-daemon==1.6 +smbus==1.1 +wsgiref==0.1.2
--- a/py/sensor_ds18b20.py Thu Jan 30 22:56:05 2014 +0800 +++ b/py/sensor_ds18b20.py Thu Jan 30 22:56:17 2014 +0800 @@ -58,6 +58,9 @@ D("no match") return None temp = int(match.groups(1)[0]) / 1000.0 + if temp > 80: + E("Problem reading sensor '%s': %f" % (s, temp)) + return None return temp except Exception, e: EX("Problem reading sensor '%s': %s" % (s, str(e))) @@ -74,7 +77,11 @@ def sensor_names(self): """ Returns a sequence of sensorname """ slaves_path = os.path.join(self.master_dir, "w1_master_slaves") - names = open(slaves_path, 'r').read().split() + contents = open(slaves_path, 'r').read() + if 'not found' in contents: + E("No W1 sensors found") + return [] + names = contents.split() return names def wort_name(self):
--- a/py/tempserver.py Thu Jan 30 22:56:05 2014 +0800 +++ b/py/tempserver.py Thu Jan 30 22:56:17 2014 +0800 @@ -6,7 +6,7 @@ import gevent import gevent.monkey -import lockfile +import lockfile.pidlockfile import daemon import utils @@ -103,9 +103,24 @@ def main(): setup_logging() - pidpath = os.path.join(os.path.dirname(__file__), 'tempserver-lock') - pidf = lockfile.FileLock(pidpath, threaded=False) - pidf.acquire(0) + heredir = os.path.abspath(os.path.dirname(__file__)) + pidpath = os.path.join(heredir, 'tempserver.pid') + pidf = lockfile.pidlockfile.PIDLockFile(pidpath, threaded=False) + try: + pidf.acquire(0) + pidf.release() + except lockfile.AlreadyLocked, e: + pid = pidf.read_pid() + print>>sys.stderr, "Locked by PID %d" % pid + if pid > 0: + try: + os.kill(pid, 0) + # must still be running PID + raise e + except OSError: + # isn't still running, steal the lock + print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) + pidf.break_lock() if '--daemon' in sys.argv: logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log')