- add startat parameter to profile runs to allow for restarting at any point in a run. handle power outages, accidently hitting stop button etc.

This commit is contained in:
jbruce12000 2018-12-21 15:13:12 -05:00
parent c32b6970ca
commit 5e5abe5b32
3 changed files with 20 additions and 3 deletions

7
api.md
View File

@ -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 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

View File

@ -51,6 +51,12 @@ def handle_api():
wanted = bottle.request.json['profile'] wanted = bottle.request.json['profile']
log.info('api requested run of profile = %s' % wanted) 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 # get the wanted profile/kiln schedule
profile = find_profile(wanted) profile = find_profile(wanted)
if profile is None: if profile is None:
@ -59,7 +65,7 @@ def handle_api():
# FIXME juggling of json should happen in the Profile class # FIXME juggling of json should happen in the Profile class
profile_json = json.dumps(profile) profile_json = json.dumps(profile)
profile = Profile(profile_json) profile = Profile(profile_json)
oven.run_profile(profile) oven.run_profile(profile,startat=startat)
ovenWatcher.record(profile) ovenWatcher.record(profile)
return { "success" : True } return { "success" : True }

View File

@ -86,12 +86,13 @@ class Oven (threading.Thread):
self.set_heat(False) self.set_heat(False)
self.pid = PID(ki=config.pid_ki, kd=config.pid_kd, kp=config.pid_kp) 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) log.info("Running schedule %s" % profile.name)
self.profile = profile self.profile = profile
self.totaltime = profile.get_duration() self.totaltime = profile.get_duration()
self.state = Oven.STATE_RUNNING self.state = Oven.STATE_RUNNING
self.start_time = datetime.datetime.now() self.start_time = datetime.datetime.now()
self.startat = startat * 60
log.info("Starting") log.info("Starting")
def abort_run(self): def abort_run(self):
@ -108,7 +109,10 @@ class Oven (threading.Thread):
self.runtime += 0.5 self.runtime += 0.5
else: else:
runtime_delta = datetime.datetime.now() - self.start_time 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) self.target = self.profile.get_target_temperature(self.runtime)
pid = self.pid.compute(self.target, self.temp_sensor.temperature) pid = self.pid.compute(self.target, self.temp_sensor.temperature)