From df7ee9e234c6c701b9e594909a1f3cf3c14736c0 Mon Sep 17 00:00:00 2001 From: jbruce12000 Date: Sun, 30 Jun 2024 11:44:45 -0400 Subject: [PATCH] add pause and resume to api --- docs/api.md | 8 ++++++++ kiln-controller.py | 8 ++++++++ lib/oven.py | 10 +++++++++- public/assets/js/picoreflow.js | 11 +++++------ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/api.md b/docs/api.md index 530d9c3..47fd6d9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -18,3 +18,11 @@ post a memo stats for currently running schedule curl -X GET http://0.0.0.0:8081/api/stats + +pause a run (maintain current temperature until resume) + + curl -d '{"cmd":"pause"}' -H "Content-Type: application/json" -X POST http://0.0.0.0:8081/api + +resume a paused run + + curl -d '{"cmd":"resume"}' -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 a845d63..595286a 100755 --- a/kiln-controller.py +++ b/kiln-controller.py @@ -84,6 +84,14 @@ def handle_api(): oven.run_profile(profile, startat=startat, allow_seek=allow_seek) ovenWatcher.record(profile) + if bottle.request.json['cmd'] == 'pause': + log.info("api pause command received") + oven.state = 'PAUSED' + + if bottle.request.json['cmd'] == 'resume': + log.info("api resume command received") + oven.state = 'RUNNING' + if bottle.request.json['cmd'] == 'stop': log.info("api stop command received") oven.abort_run() diff --git a/lib/oven.py b/lib/oven.py index 9496698..41edece 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -541,6 +541,14 @@ class Oven(threading.Thread): self.automatic_restart() time.sleep(1) continue + if self.state == "PAUSED": + self.start_time = self.get_start_time() + self.update_runtime() + self.update_target_temp() + self.heat_then_cool() + self.reset_if_emergency() + self.reset_if_schedule_ended() + continue if self.state == "RUNNING": self.update_cost() self.save_automatic_restart_state() @@ -806,7 +814,7 @@ class PID(): log.info("kiln outside pid control window, max heating") output = 1 if config.throttle_below_temp and config.throttle_percent: - if ispoint <= config.throttle_below_temp: + if setpoint <= config.throttle_below_temp: output = config.throttle_percent/100 log.info("max heating throttled at %d percent below %d degrees to prevent overshoot" % (config.throttle_percent,config.throttle_below_temp)) else: diff --git a/public/assets/js/picoreflow.js b/public/assets/js/picoreflow.js index 7d38a92..a2b67e0 100644 --- a/public/assets/js/picoreflow.js +++ b/public/assets/js/picoreflow.js @@ -502,9 +502,6 @@ $(document).ready(function() ws_status.onmessage = function(e) { - console.log("received status data") - console.log(e.data); - x = JSON.parse(e.data); if (x.type == "backlog") { @@ -528,11 +525,11 @@ $(document).ready(function() if(state!="EDIT") { state = x.state; - if (state!=state_last) { - if(state_last == "RUNNING") + if(state_last == "RUNNING" && state != "PAUSED" ) { + console.log(state); $('#target_temp').html('---'); updateProgress(0); $.bootstrapGrowl(" Run completed", { @@ -579,7 +576,9 @@ $(document).ready(function() if (heat_rate > 9999) { heat_rate = 9999; } if (heat_rate < -9999) { heat_rate = -9999; } $('#heat_rate').html(heat_rate); - $('#heat').html('
') + if (typeof x.pidstats !== 'undefined') { + $('#heat').html('
') + } if (x.cool > 0.5) { $('#cool').addClass("ds-led-cool-active"); } else { $('#cool').removeClass("ds-led-cool-active"); } if (x.air > 0.5) { $('#air').addClass("ds-led-air-active"); } else { $('#air').removeClass("ds-led-air-active"); } if (x.temperature > hazardTemp()) { $('#hazard').addClass("ds-led-hazard-active"); } else { $('#hazard').removeClass("ds-led-hazard-active"); }