From 5e5abe5b327eb48b80c19bcb1092e2ffd7628751 Mon Sep 17 00:00:00 2001 From: jbruce12000 Date: Fri, 21 Dec 2018 15:13:12 -0500 Subject: [PATCH] - add startat parameter to profile runs to allow for restarting at any point in a run. handle power outages, accidently hitting stop button etc. --- api.md | 7 +++++++ kiln-controller.py | 8 +++++++- lib/oven.py | 8 ++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api.md b/api.md index 2ca75cd..066b661 100644 --- a/api.md +++ b/api.md @@ -1,2 +1,9 @@ +# start a run + curl -d '{"cmd":"run", "profile":"cone-05-lo"}' -H "Content-Type: application/json" -X POST http://0.0.0.0:8081/api +# skip the first part of a run +# restart the kiln on a specific profile and start at minute 60 + +curl -d '{"cmd":"run", "profile":"cone-05-lo","startat":60}' -H "Content-Type: application/json" -X POST http://0.0.0.0:8081/api + diff --git a/kiln-controller.py b/kiln-controller.py index 874491c..7b38f26 100755 --- a/kiln-controller.py +++ b/kiln-controller.py @@ -51,6 +51,12 @@ def handle_api(): wanted = bottle.request.json['profile'] log.info('api requested run of profile = %s' % wanted) + # start at a specific minute in the schedule + # for restarting and skipping over early parts of a schedule + startat = 0; + if 'startat' in bottle.request.json: + startat = bottle.request.json['startat'] + # get the wanted profile/kiln schedule profile = find_profile(wanted) if profile is None: @@ -59,7 +65,7 @@ def handle_api(): # FIXME juggling of json should happen in the Profile class profile_json = json.dumps(profile) profile = Profile(profile_json) - oven.run_profile(profile) + oven.run_profile(profile,startat=startat) ovenWatcher.record(profile) return { "success" : True } diff --git a/lib/oven.py b/lib/oven.py index e5b0bf3..fd63318 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -86,12 +86,13 @@ class Oven (threading.Thread): self.set_heat(False) self.pid = PID(ki=config.pid_ki, kd=config.pid_kd, kp=config.pid_kp) - def run_profile(self, profile): + def run_profile(self, profile, startat=0): log.info("Running schedule %s" % profile.name) self.profile = profile self.totaltime = profile.get_duration() self.state = Oven.STATE_RUNNING self.start_time = datetime.datetime.now() + self.startat = startat * 60 log.info("Starting") def abort_run(self): @@ -108,7 +109,10 @@ class Oven (threading.Thread): self.runtime += 0.5 else: runtime_delta = datetime.datetime.now() - self.start_time - self.runtime = runtime_delta.total_seconds() + if self.startat > 0: + self.runtime = self.startat + runtime_delta.total_seconds(); + else: + self.runtime = runtime_delta.total_seconds() self.target = self.profile.get_target_temperature(self.runtime) pid = self.pid.compute(self.target, self.temp_sensor.temperature)