From 03b5bd9c26d961acd6147f7c085e907ec34fa4c7 Mon Sep 17 00:00:00 2001 From: jbruce12000 Date: Fri, 1 Jul 2022 15:39:07 -0400 Subject: [PATCH 1/7] creating the kiln-profiles branch for using the new kiln-profiles repo --- config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index caafcfe..8edd0c1 100644 --- a/config.py +++ b/config.py @@ -14,7 +14,7 @@ log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s' ### Server listening_ip = "0.0.0.0" -listening_port = 8081 +listening_port = 8082 ### Cost Estimate kwh_rate = 0.1319 # Rate in currency_type to calculate cost to run job @@ -167,3 +167,10 @@ automatic_restarts = True automatic_restart_window = 15 # max minutes since power outage automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'state.json')) +######################################################################## +# load kiln profiles from this directory +# created a repo where anyone can contribute profiles. The objective is +# to load profiles from this repository by default. +# See https://github.com/jbruce12000/kiln-profiles +kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..','kiln-profiles','pottery')) + From 1e97db2e22d4627107e7755452fe7d8f98d182b9 Mon Sep 17 00:00:00 2001 From: jbruce12000 Date: Fri, 1 Jul 2022 15:49:20 -0400 Subject: [PATCH 2/7] set config location for loading profiles and load on start-up --- config.py | 1 + kiln-controller.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 8edd0c1..ea2365e 100644 --- a/config.py +++ b/config.py @@ -172,5 +172,6 @@ automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __f # created a repo where anyone can contribute profiles. The objective is # to load profiles from this repository by default. # See https://github.com/jbruce12000/kiln-profiles +#kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),"storage", "profiles")) kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..','kiln-profiles','pottery')) diff --git a/kiln-controller.py b/kiln-controller.py index 531aba2..7e9e039 100755 --- a/kiln-controller.py +++ b/kiln-controller.py @@ -28,7 +28,7 @@ log.info("Starting kiln controller") script_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, script_dir + '/lib/') -profile_path = os.path.join(script_dir, "storage", "profiles") +profile_path = config.kiln_profiles_directory from oven import SimulatedOven, RealOven, Profile from ovenWatcher import OvenWatcher From 6209d61b4846bca1b438c22566728b5b29c3cd4b Mon Sep 17 00:00:00 2001 From: jbruce Date: Wed, 6 Jul 2022 07:43:59 -0400 Subject: [PATCH 3/7] wrap log statement in try --- watcher.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/watcher.py b/watcher.py index 323e2fa..513ca85 100755 --- a/watcher.py +++ b/watcher.py @@ -61,7 +61,10 @@ class Watcher(object): if self.has_errors(): self.bad_checks = self.bad_checks + 1 else: - log.info("OK temp=%0.2f target=%0.2f error=%0.2f" % (self.stats['ispoint'],self.stats['setpoint'],self.stats['err'])) + try: + log.info("OK temp=%0.2f target=%0.2f error=%0.2f" % (self.stats['ispoint'],self.stats['setpoint'],self.stats['err'])) + except: + pass if self.bad_checks >= self.bad_check_limit: msg = "error kiln needs help. %s" % json.dumps(self.stats,indent=2, sort_keys=True) From 8fbb3ab649d46e1a913ccd637d3b240e7d43ab93 Mon Sep 17 00:00:00 2001 From: jbruce Date: Thu, 11 Aug 2022 08:18:25 -0400 Subject: [PATCH 4/7] adding configurable emergencies --- config.py | 22 ++++++++++++++-------- lib/oven.py | 10 +++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/config.py b/config.py index ea2365e..b74ba20 100644 --- a/config.py +++ b/config.py @@ -130,12 +130,6 @@ pid_control_window = 5 #degrees # cheap thermocouple. Invest in a better thermocouple. thermocouple_offset=0 -# some kilns/thermocouples start erroneously reporting "short" -# errors at higher temperatures due to plasma forming in the kiln. -# Set this to False to ignore these errors and assume the temperature -# reading was correct anyway -honour_theromocouple_short_errors = False - # number of samples of temperature to average. # If you suffer from the high temperature kiln issue and have set # honour_theromocouple_short_errors to False, @@ -145,13 +139,25 @@ temperature_average_samples = 40 # Thermocouple AC frequency filtering - set to True if in a 50Hz locale, else leave at False for 60Hz locale ac_freq_50hz = False +######################################################################## +# Emergencies - or maybe not +######################################################################## # There are all kinds of emergencies that can happen including: # - temperature is too high (emergency_shutoff_temp exceeded) # - lost connection to thermocouple # - unknown error with thermocouple # - too many errors in a short period from thermocouple -# and some people just want to ignore all of that and just log the emergencies but do not quit -ignore_emergencies = False +# but in some cases, you might want to ignore a specific error, log it, +# and continue running your profile. +ignore_temp_too_high = False +ignore_lost_connection_tc = False +ignore_unknown_tc_error = False +ignore_too_many_tc_errors = False +# some kilns/thermocouples start erroneously reporting "short" +# errors at higher temperatures due to plasma forming in the kiln. +# Set this to True to ignore these errors and assume the temperature +# reading was correct anyway +ignore_tc_short_errors = False ######################################################################## # automatic restarts - if you have a power brown-out and the raspberry pi diff --git a/lib/oven.py b/lib/oven.py index 35a06f6..301e939 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -164,7 +164,7 @@ class TempSensorReal(TempSensor): self.unknownError = self.thermocouple.unknownError is_bad_value = self.noConnection | self.unknownError - if config.honour_theromocouple_short_errors: + if not config.ignore_tc_short_errors: is_bad_value |= self.shortToGround | self.shortToVCC if not is_bad_value: @@ -273,22 +273,22 @@ class Oven(threading.Thread): if (self.board.temp_sensor.temperature + config.thermocouple_offset >= config.emergency_shutoff_temp): log.info("emergency!!! temperature too high") - if not config.ignore_emergencies == True: + if config.ignore_temp_too_high == False: self.abort_run() if self.board.temp_sensor.noConnection: log.info("emergency!!! lost connection to thermocouple") - if not config.ignore_emergencies == True: + if config.ignore_lost_connection_tc == False: self.abort_run() if self.board.temp_sensor.unknownError: log.info("emergency!!! unknown thermocouple error") - if not config.ignore_emergencies == True: + if config.ignore_unknown_tc_error == False: self.abort_run() if self.board.temp_sensor.bad_percent > 30: log.info("emergency!!! too many errors in a short period") - if not config.ignore_emergencies == True: + if config.ignore_too_many_tc_errors == False: self.abort_run() def reset_if_schedule_ended(self): From e45709a5a4098f870735d609354466a79022f436 Mon Sep 17 00:00:00 2001 From: jbruce Date: Wed, 31 Aug 2022 21:45:34 -0400 Subject: [PATCH 5/7] initial changes for cost calculation --- config.py | 15 +++++++++++---- lib/oven.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index b74ba20..5f0537e 100644 --- a/config.py +++ b/config.py @@ -16,8 +16,15 @@ log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s' listening_ip = "0.0.0.0" listening_port = 8082 -### Cost Estimate -kwh_rate = 0.1319 # Rate in currency_type to calculate cost to run job +######################################################################## +# Cost Information +# +# This is used to calculate a cost estimate before a run. It's also used +# to produce the actual cost at the end of a run. My kiln has three +# elements that when my switches are set to high, consume 9460 watts. + +kwh_rate = 0.1319 # cost per kilowatt hour per currency_type to calculate cost to run job +kw_elements = 0.9460 # if the kiln elements are on, the wattage in kilowatts currency_type = "$" # Currency Symbol to show when calculating cost to run job ######################################################################## @@ -178,6 +185,6 @@ automatic_restart_state_file = os.path.abspath(os.path.join(os.path.dirname( __f # created a repo where anyone can contribute profiles. The objective is # to load profiles from this repository by default. # See https://github.com/jbruce12000/kiln-profiles -#kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),"storage", "profiles")) -kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..','kiln-profiles','pottery')) +kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),"storage", "profiles")) +#kiln_profiles_directory = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..','kiln-profiles','pottery')) diff --git a/lib/oven.py b/lib/oven.py index 301e939..4773570 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -204,6 +204,7 @@ class Oven(threading.Thread): self.reset() def reset(self): + self.cost = 0 self.state = "IDLE" self.profile = None self.start_time = 0 @@ -296,6 +297,13 @@ class Oven(threading.Thread): log.info("schedule ended, shutting down") self.abort_run() + def update_cost(self): + if self.heat: + cost = (config.kwh_rate * config.kw_elements) * ((self.heat)/3600) + else: + cost = 0 + self.cost = self.cost + cost + def get_state(self): temp = 0 try: @@ -306,6 +314,7 @@ class Oven(threading.Thread): pass state = { + 'cost': self.cost, 'runtime': self.runtime, 'temperature': temp, 'target': self.target, @@ -368,6 +377,7 @@ class Oven(threading.Thread): profile_json = json.dumps(json.load(infile)) profile = Profile(profile_json) self.run_profile(profile,startat=startat) + self.cost = d["cost"] time.sleep(1) self.ovenwatcher.record(profile) @@ -383,6 +393,7 @@ class Oven(threading.Thread): time.sleep(1) continue if self.state == "RUNNING": + self.update_cost() self.save_automatic_restart_state() self.kiln_must_catch_up() self.update_runtime() From 7b646c95cff3ec4630e103c8abdbb3e9566be41b Mon Sep 17 00:00:00 2001 From: jbruce12000 Date: Sun, 11 Sep 2022 14:10:38 -0400 Subject: [PATCH 6/7] added cost to web interface --- config.py | 2 +- lib/oven.py | 1 + public/assets/js/picoreflow.js | 2 ++ public/index.html | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 5f0537e..30ca0e5 100644 --- a/config.py +++ b/config.py @@ -24,7 +24,7 @@ listening_port = 8082 # elements that when my switches are set to high, consume 9460 watts. kwh_rate = 0.1319 # cost per kilowatt hour per currency_type to calculate cost to run job -kw_elements = 0.9460 # if the kiln elements are on, the wattage in kilowatts +kw_elements = 9.460 # if the kiln elements are on, the wattage in kilowatts currency_type = "$" # Currency Symbol to show when calculating cost to run job ######################################################################## diff --git a/lib/oven.py b/lib/oven.py index 4773570..7503fac 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -295,6 +295,7 @@ class Oven(threading.Thread): def reset_if_schedule_ended(self): if self.runtime > self.totaltime: log.info("schedule ended, shutting down") + log.info("total cost = %s%.2f" % (config.currency_type,self.cost)) self.abort_run() def update_cost(self): diff --git a/public/assets/js/picoreflow.js b/public/assets/js/picoreflow.js index 90e3ecd..95c6ede 100644 --- a/public/assets/js/picoreflow.js +++ b/public/assets/js/picoreflow.js @@ -548,6 +548,8 @@ $(document).ready(function() updateProgress(parseFloat(x.runtime)/parseFloat(x.totaltime)*100); $('#state').html('' + eta + ''); $('#target_temp').html(parseInt(x.target)); + $('#cost').html(x.currency_type + parseFloat(x.cost).toFixed(2)); + } diff --git a/public/index.html b/public/index.html index 08b2d69..b37b682 100644 --- a/public/index.html +++ b/public/index.html @@ -29,12 +29,14 @@
Sensor Temp
Target Temp
+
Cost
Status
25°C
---°C
+
0.00
\l[I
From 14a7d744790c6eb6c67dd0e763674c13e44e5aaf Mon Sep 17 00:00:00 2001 From: jbruce Date: Thu, 13 Oct 2022 12:41:47 -0400 Subject: [PATCH 7/7] change comment about when cost settings get used --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 30ca0e5..3f89452 100644 --- a/config.py +++ b/config.py @@ -20,7 +20,7 @@ listening_port = 8082 # Cost Information # # This is used to calculate a cost estimate before a run. It's also used -# to produce the actual cost at the end of a run. My kiln has three +# to produce the actual cost during a run. My kiln has three # elements that when my switches are set to high, consume 9460 watts. kwh_rate = 0.1319 # cost per kilowatt hour per currency_type to calculate cost to run job