From d86f0c081956d680680c8e11127ef384d543a588 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 10:30:15 -0500 Subject: [PATCH 01/21] Adjust temperature on enviro indoor when on usb --- enviro/__init__.py | 4 ++-- enviro/boards/grow.py | 2 +- enviro/boards/indoor.py | 16 +++++++++++++--- enviro/boards/urban.py | 2 +- enviro/boards/weather.py | 2 +- enviro/config_template.py | 6 +++++- main.py | 6 +++--- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 07b1633..2305170 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -280,7 +280,7 @@ def wake_reason_name(wake_reason): return names.get(wake_reason) # get the readings from the on board sensors -def get_sensor_readings(): +def get_sensor_readings(config): seconds_since_last = 0 now_str = helpers.datetime_string() if helpers.file_exists("last_time.txt"): @@ -301,7 +301,7 @@ def get_sensor_readings(): logging.info(f" - seconds since last reading: {seconds_since_last}") - readings = get_board().get_sensor_readings(seconds_since_last) + readings = get_board().get_sensor_readings(seconds_since_last, config) readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed # write out the last time log diff --git a/enviro/boards/grow.py b/enviro/boards/grow.py index cb0e081..acba410 100644 --- a/enviro/boards/grow.py +++ b/enviro/boards/grow.py @@ -98,7 +98,7 @@ def water(moisture_levels): drip_noise() time.sleep(0.5) -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, config): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index a06bc24..737ab2f 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -40,12 +40,22 @@ def colour_temperature_from_rgbc(r, g, b, c): ct = 10000 return round(ct) -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, config): data = bme688.read() temperature = round(data[0], 2) - pressure = round(data[1] / 100.0, 2) humidity = round(data[2], 2) + + # Compensate for additional heating when on usb power. Both the temperature + # and relative humidity are affected. + # The humidity correction is from https://github.com/pimoroni/pimoroni-pico + if config.usb_power: + corrected_temperature = temperature - config.usb_power_temperature_offset + dewpoint = temperature - ((100 - humidity) / 5) + humidity = 100 - (5 * (corrected_temperature - dewpoint)) + temperature = corrected_temperature + + pressure = round(data[1] / 100.0, 2) gas_resistance = round(data[3]) # an approximate air quality calculation that accounts for the effect of # humidity on the gas sensor @@ -64,4 +74,4 @@ def get_sensor_readings(seconds_since_last): "aqi": aqi, "luminance": lux_from_rgbc(r, g, b, c), "color_temperature": colour_temperature_from_rgbc(r, g, b, c) - }) \ No newline at end of file + }) diff --git a/enviro/boards/urban.py b/enviro/boards/urban.py index 6f5a07e..716fc47 100644 --- a/enviro/boards/urban.py +++ b/enviro/boards/urban.py @@ -34,7 +34,7 @@ def particulates(particulate_data, measure): multiplier = 10 if measure >= PM0_3_PER_LITRE else 1 return ((particulate_data[measure * 2] << 8) | particulate_data[measure * 2 + 1]) * multiplier -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, config): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/weather.py b/enviro/boards/weather.py index 3fc4b8e..663b144 100644 --- a/enviro/boards/weather.py +++ b/enviro/boards/weather.py @@ -180,7 +180,7 @@ def rainfall(seconds_since_last): return amount, per_second -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, config): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/config_template.py b/enviro/config_template.py index 9556813..a0e09f1 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -47,4 +47,8 @@ auto_water = False moisture_target_a = 50 moisture_target_b = 50 -moisture_target_c = 50 \ No newline at end of file +moisture_target_c = 50 + +# compensate for usb_power +usb_power = False +usb_power_temperature_offset = 4 diff --git a/main.py b/main.py index 95eff3b..c17e45f 100644 --- a/main.py +++ b/main.py @@ -68,14 +68,14 @@ # TODO should the board auto take a reading when the timer has been set, or wait for the time? # take a reading from the onboard sensors enviro.logging.debug(f"> taking new reading") - reading = enviro.get_sensor_readings() + reading = enviro.get_sensor_readings(enviro.config) # here you can customise the sensor readings by adding extra information # or removing readings that you don't want, for example: # - # del readings["temperature"] # remove the temperature reading + # del reading["temperature"] # remove the temperature reading # - # readings["custom"] = my_reading() # add my custom reading value + # reading["custom"] = my_reading() # add my custom reading value # is an upload destination set? if enviro.config.destination: From 42a64345596881cd4bb33fc9d7c0a8171afc9371 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:33:31 -0500 Subject: [PATCH 02/21] Remove bad humidity adjustment logic --- enviro/boards/indoor.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index 737ab2f..40b5fd1 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -44,18 +44,17 @@ def get_sensor_readings(seconds_since_last, config): data = bme688.read() temperature = round(data[0], 2) - humidity = round(data[2], 2) - # Compensate for additional heating when on usb power. Both the temperature - # and relative humidity are affected. - # The humidity correction is from https://github.com/pimoroni/pimoroni-pico + # Compensate for additional heating when on usb power. if config.usb_power: - corrected_temperature = temperature - config.usb_power_temperature_offset - dewpoint = temperature - ((100 - humidity) / 5) - humidity = 100 - (5 * (corrected_temperature - dewpoint)) - temperature = corrected_temperature + temperature = temperature - config.usb_power_temperature_offset + + # TODO - update humidity + # calculate absolute humidity with original temp/humidity values + # use absolute humidity to figure out the new humidity at the adjusted temperature value pressure = round(data[1] / 100.0, 2) + humidity = round(data[2], 2) gas_resistance = round(data[3]) # an approximate air quality calculation that accounts for the effect of # humidity on the gas sensor From 14a234ba660257a8f57d9c6344f814af4c50378a Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:34:06 -0500 Subject: [PATCH 03/21] Automatically detect battery vs usb power --- enviro/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/enviro/__init__.py b/enviro/__init__.py index 2305170..fa24fe7 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -1,6 +1,7 @@ # keep the power rail alive by holding VSYS_EN high as early as possible # =========================================================================== from enviro.constants import * +from enviro.provisioning import write_config from machine import Pin hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT, value=True) @@ -469,6 +470,10 @@ def sleep(time_override=None): rtc.set_alarm(0, minute, hour) rtc.enable_alarm_interrupt(True) + # assume we're running on battery power + config.usb_power = False + write_config() + # disable the vsys hold, causing us to turn off logging.info(" - shutting down") hold_vsys_en_pin.init(Pin.IN) @@ -477,6 +482,11 @@ def sleep(time_override=None): # case we can't (and don't need to) sleep. stop_activity_led() + # indicate that we're running on usb power - which requires temperature + # and humidity adjustments. + config.usb_power = True + write_config() + # if running via mpremote/pyboard.py with a remote mount then we can't # reset the board so just exist if phew.remote_mount: From 2e502dcdae633ca970275eccaf6647af542310f1 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:50:35 -0500 Subject: [PATCH 04/21] Fix import issue --- enviro/__init__.py | 22 +++++++++++++++++++++- enviro/provisioning.py | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index fa24fe7..99f7df0 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -1,7 +1,6 @@ # keep the power rail alive by holding VSYS_EN high as early as possible # =========================================================================== from enviro.constants import * -from enviro.provisioning import write_config from machine import Pin hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT, value=True) @@ -471,6 +470,7 @@ def sleep(time_override=None): rtc.enable_alarm_interrupt(True) # assume we're running on battery power + logging.debug("assume battery power in config") config.usb_power = False write_config() @@ -484,6 +484,7 @@ def sleep(time_override=None): # indicate that we're running on usb power - which requires temperature # and humidity adjustments. + logging.debug("switching config to usb power") config.usb_power = True write_config() @@ -508,3 +509,22 @@ def sleep(time_override=None): # reset the board machine.reset() + +# TODO - refactor +# write the current values in config to the config.py file +def write_config(): + lines = [] + with open("config.py", "r") as infile: + lines = infile.read().split("\n") + + for i in range(0, len(lines)): + line = lines[i] + parts = line.split("=", 1) + if len(parts) == 2: + key = parts[0].strip() + if hasattr(config, key): + value = getattr(config, key) + lines[i] = f"{key} = {repr(value)}" + + with open("config.py", "w") as outfile: + outfile.write("\n".join(lines)) diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 1baaef2..24ab3fa 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -207,4 +207,4 @@ def catchall(request): logging.info(" - client connected!", ap.status("stations")[0]) logging.info("> running provisioning application...") -server.run(host="0.0.0.0", port=80) \ No newline at end of file +server.run(host="0.0.0.0", port=80) From 61de482b47fc95803000dee4613313c8acc8d66b Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:33:31 -0500 Subject: [PATCH 05/21] Remove bad humidity adjustment logic From 4ba13161a11cefa0248098e9383e0459b92d98ee Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:34:06 -0500 Subject: [PATCH 06/21] Automatically detect battery vs usb power --- enviro/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/enviro/__init__.py b/enviro/__init__.py index 99f7df0..e91bf37 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -1,6 +1,7 @@ # keep the power rail alive by holding VSYS_EN high as early as possible # =========================================================================== from enviro.constants import * +from enviro.provisioning import write_config from machine import Pin hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT, value=True) From 78f18b66c95baaec1602f157c67eb32c8e9a5591 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:50:35 -0500 Subject: [PATCH 07/21] Fix import issue --- enviro/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index e91bf37..99f7df0 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -1,7 +1,6 @@ # keep the power rail alive by holding VSYS_EN high as early as possible # =========================================================================== from enviro.constants import * -from enviro.provisioning import write_config from machine import Pin hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT, value=True) From 7aac82dda793f88c4fdce48320d6ca4291ed977a Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 12:58:25 -0500 Subject: [PATCH 08/21] Clean up code --- enviro/__init__.py | 23 ++--------------------- enviro/boards/indoor.py | 3 ++- enviro/helpers.py | 17 +++++++++++++++++ enviro/provisioning.py | 30 ++++++------------------------ 4 files changed, 27 insertions(+), 46 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 99f7df0..1829366 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -472,7 +472,7 @@ def sleep(time_override=None): # assume we're running on battery power logging.debug("assume battery power in config") config.usb_power = False - write_config() + helpers.write_config(config) # disable the vsys hold, causing us to turn off logging.info(" - shutting down") @@ -486,7 +486,7 @@ def sleep(time_override=None): # and humidity adjustments. logging.debug("switching config to usb power") config.usb_power = True - write_config() + helpers.write_config(config) # if running via mpremote/pyboard.py with a remote mount then we can't # reset the board so just exist @@ -509,22 +509,3 @@ def sleep(time_override=None): # reset the board machine.reset() - -# TODO - refactor -# write the current values in config to the config.py file -def write_config(): - lines = [] - with open("config.py", "r") as infile: - lines = infile.read().split("\n") - - for i in range(0, len(lines)): - line = lines[i] - parts = line.split("=", 1) - if len(parts) == 2: - key = parts[0].strip() - if hasattr(config, key): - value = getattr(config, key) - lines[i] = f"{key} = {repr(value)}" - - with open("config.py", "w") as outfile: - outfile.write("\n".join(lines)) diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index 40b5fd1..139c7d3 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -51,7 +51,8 @@ def get_sensor_readings(seconds_since_last, config): # TODO - update humidity # calculate absolute humidity with original temp/humidity values - # use absolute humidity to figure out the new humidity at the adjusted temperature value + # use absolute humidity to figure out the new relative humidity at the + # adjusted temperature value pressure = round(data[1] / 100.0, 2) humidity = round(data[2], 2) diff --git a/enviro/helpers.py b/enviro/helpers.py index a9ead63..a9cb93f 100644 --- a/enviro/helpers.py +++ b/enviro/helpers.py @@ -57,3 +57,20 @@ def copy_file(source, target): if not chunk: break outfile.write(chunk) + +def write_config(config): + lines = [] + with open("config.py", "r") as infile: + lines = infile.read().split("\n") + + for i in range(0, len(lines)): + line = lines[i] + parts = line.split("=", 1) + if len(parts) == 2: + key = parts[0].strip() + if hasattr(config, key): + value = getattr(config, key) + lines[i] = f"{key} = {repr(value)}" + + with open("config.py", "w") as outfile: + outfile.write("\n".join(lines)) diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 24ab3fa..9be79f7 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -12,24 +12,6 @@ if not helpers.file_exists("config.py"): helpers.copy_file("enviro/config_template.py", "config.py") -# write the current values in config to the config.py file -def write_config(): - lines = [] - with open("config.py", "r") as infile: - lines = infile.read().split("\n") - - for i in range(0, len(lines)): - line = lines[i] - parts = line.split("=", 1) - if len(parts) == 2: - key = parts[0].strip() - if hasattr(config, key): - value = getattr(config, key) - lines[i] = f"{key} = {repr(value)}" - - with open("config.py", "w") as outfile: - outfile.write("\n".join(lines)) - import config @@ -71,7 +53,7 @@ def provision_welcome(request): def provision_step_1_nickname(request): if request.method == "POST": config.nickname = request.form["nickname"] - write_config() + helpers.write_config(config) return redirect(f"http://{DOMAIN}/provision-step-2-wifi") else: return render_template("enviro/html/provision-step-1-nickname.html", board=model) @@ -82,7 +64,7 @@ def provision_step_2_wifi(request): if request.method == "POST": config.wifi_ssid = request.form["wifi_ssid"] config.wifi_password = request.form["wifi_password"] - write_config() + helpers.write_config(config) return redirect(f"http://{DOMAIN}/provision-step-3-logging") else: return render_template("enviro/html/provision-step-2-wifi.html", board=model) @@ -93,7 +75,7 @@ def provision_step_3_logging(request): if request.method == "POST": config.reading_frequency = int(request.form["reading_frequency"]) config.upload_frequency = int(request.form["upload_frequency"]) if request.form["upload_frequency"] else None - write_config() + helpers.write_config(config) return redirect(f"http://{DOMAIN}/provision-step-4-destination") else: return render_template("enviro/html/provision-step-3-logging.html", board=model) @@ -124,7 +106,7 @@ def provision_step_4_destination(request): config.influxdb_token = request.form["influxdb_token"] config.influxdb_bucket = request.form["influxdb_bucket"] - write_config() + helpers.write_config(config) if model == "grow": return redirect(f"http://{DOMAIN}/provision-step-grow-sensors") @@ -153,7 +135,7 @@ def provision_step_grow_sensors(request): except ValueError: pass - write_config() + helpers.write_config(config) return redirect(f"http://{DOMAIN}/provision-step-5-done") else: @@ -163,7 +145,7 @@ def provision_step_grow_sensors(request): @server.route("/provision-step-5-done", methods=["GET", "POST"]) def provision_step_5_done(request): config.provisioned = True - write_config() + helpers.write_config(config) # a post request to the done handler means we're finished and # should reset the board From 999fd8493e151fe671795aa16e8e4087685290c8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 15:58:13 -0500 Subject: [PATCH 09/21] Adjust humidity for the corrected temperature --- enviro/boards/indoor.py | 16 +++++++-------- enviro/constants.py | 5 +++++ enviro/helpers.py | 43 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index 139c7d3..5fe4c42 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -1,3 +1,4 @@ +import enviro.helpers as helpers import math from breakout_bme68x import BreakoutBME68X from breakout_bh1745 import BreakoutBH1745 @@ -44,18 +45,17 @@ def get_sensor_readings(seconds_since_last, config): data = bme688.read() temperature = round(data[0], 2) + humidity = round(data[2], 2) - # Compensate for additional heating when on usb power. + # Compensate for additional heating when on usb power - this also changes the + # relative humidity value. if config.usb_power: - temperature = temperature - config.usb_power_temperature_offset - - # TODO - update humidity - # calculate absolute humidity with original temp/humidity values - # use absolute humidity to figure out the new relative humidity at the - # adjusted temperature value + adjusted_temperature = temperature - config.usb_power_temperature_offset + absolute_humidity = helpers.relative_to_absolute_humidity(humidity, temperature) + humidity = helpers.absolute_to_relative_humidity(absolute_humidity, adjusted_temperature) + temperature = adjusted_temperature pressure = round(data[1] / 100.0, 2) - humidity = round(data[2], 2) gas_resistance = round(data[3]) # an approximate air quality calculation that accounts for the effect of # humidity on the gas sensor diff --git a/enviro/constants.py b/enviro/constants.py index 0dadcea..b319821 100644 --- a/enviro/constants.py +++ b/enviro/constants.py @@ -40,3 +40,8 @@ UPLOAD_SUCCESS = 0 UPLOAD_FAILED = 1 UPLOAD_RATE_LIMITED = 2 + +# humidity +WATER_VAPOR_SPECIFIC_GAS_CONSTANT = 461.5 +CRITICAL_WATER_TEMPERATURE = 647.096 +CRITICAL_WATER_PRESSURE = 22064000 diff --git a/enviro/helpers.py b/enviro/helpers.py index a9cb93f..ce67f25 100644 --- a/enviro/helpers.py +++ b/enviro/helpers.py @@ -1,5 +1,5 @@ from enviro.constants import * -import machine, os, time +import machine, math, os, time # miscellany # =========================================================================== @@ -74,3 +74,44 @@ def write_config(config): with open("config.py", "w") as outfile: outfile.write("\n".join(lines)) + +# temperature and humidity helpers +# =========================================================================== + +# https://www.calctool.org/atmospheric-thermodynamics/absolute-humidity#what-is-and-how-to-calculate-absolute-humidity +def relative_to_absolute_humidity(relative_humidity, temperature_in_c): + temperature_in_k = celcius_to_kelvin(temperature_in_c) + actual_vapor_pressure = get_actual_vapor_pressure(relative_humidity, temperature_in_k) + + return actual_vapor_pressure / (WATER_VAPOR_SPECIFIC_GAS_CONSTANT * temperature_in_k) + +def absolute_to_relative_humidity(absolute_humidity, temperature_in_c): + temperature_in_k = celcius_to_kelvin(temperature_in_c) + saturation_vapor_pressure = get_saturation_vapor_pressure(temperature_in_k) + + return (WATER_VAPOR_SPECIFIC_GAS_CONSTANT * temperature_in_k * absolute_humidity) / saturation_vapor_pressure * 100 + +def celcius_to_kelvin(temperature_in_c): + return temperature_in_c + 273.15 + +# https://www.calctool.org/atmospheric-thermodynamics/absolute-humidity#actual-vapor-pressure +# http://cires1.colorado.edu/~voemel/vp.html +def get_actual_vapor_pressure(relative_humidity, temperature_in_k): + return get_saturation_vapor_pressure(temperature_in_k) * (relative_humidity / 100) + +def get_saturation_vapor_pressure(temperature_in_k): + v = 1 - (temperature_in_k / CRITICAL_WATER_TEMPERATURE) + + # empirical constants + a1 = -7.85951783 + a2 = 1.84408259 + a3 = -11.7866497 + a4 = 22.6807411 + a5 = -15.9618719 + a6 = 1.80122502 + + return CRITICAL_WATER_PRESSURE * math.exp( + CRITICAL_WATER_TEMPERATURE / + temperature_in_k * + (a1*v + a2*v**1.5 + a3*v**3 + a4*v**3.5 + a5*v**4 + a6*v**7.5) + ) From fc29bc97edfc1c6dd4b20322226ac67c65c6fafd Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 16:13:12 -0500 Subject: [PATCH 10/21] Clean up code --- enviro/__init__.py | 2 +- enviro/boards/grow.py | 2 +- enviro/boards/indoor.py | 3 ++- enviro/boards/urban.py | 2 +- enviro/boards/weather.py | 2 +- main.py | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 1829366..c4b50f9 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -280,7 +280,7 @@ def wake_reason_name(wake_reason): return names.get(wake_reason) # get the readings from the on board sensors -def get_sensor_readings(config): +def get_sensor_readings(): seconds_since_last = 0 now_str = helpers.datetime_string() if helpers.file_exists("last_time.txt"): diff --git a/enviro/boards/grow.py b/enviro/boards/grow.py index acba410..cb0e081 100644 --- a/enviro/boards/grow.py +++ b/enviro/boards/grow.py @@ -98,7 +98,7 @@ def water(moisture_levels): drip_noise() time.sleep(0.5) -def get_sensor_readings(seconds_since_last, config): +def get_sensor_readings(seconds_since_last): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index 5fe4c42..fa11239 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -3,6 +3,7 @@ from breakout_bme68x import BreakoutBME68X from breakout_bh1745 import BreakoutBH1745 +from enviro import config from enviro import i2c bme688 = BreakoutBME68X(i2c, address=0x77) @@ -41,7 +42,7 @@ def colour_temperature_from_rgbc(r, g, b, c): ct = 10000 return round(ct) -def get_sensor_readings(seconds_since_last, config): +def get_sensor_readings(seconds_since_last): data = bme688.read() temperature = round(data[0], 2) diff --git a/enviro/boards/urban.py b/enviro/boards/urban.py index 716fc47..6f5a07e 100644 --- a/enviro/boards/urban.py +++ b/enviro/boards/urban.py @@ -34,7 +34,7 @@ def particulates(particulate_data, measure): multiplier = 10 if measure >= PM0_3_PER_LITRE else 1 return ((particulate_data[measure * 2] << 8) | particulate_data[measure * 2 + 1]) * multiplier -def get_sensor_readings(seconds_since_last, config): +def get_sensor_readings(seconds_since_last): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/weather.py b/enviro/boards/weather.py index 663b144..3fc4b8e 100644 --- a/enviro/boards/weather.py +++ b/enviro/boards/weather.py @@ -180,7 +180,7 @@ def rainfall(seconds_since_last): return amount, per_second -def get_sensor_readings(seconds_since_last, config): +def get_sensor_readings(seconds_since_last): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/main.py b/main.py index c17e45f..de938bb 100644 --- a/main.py +++ b/main.py @@ -68,7 +68,7 @@ # TODO should the board auto take a reading when the timer has been set, or wait for the time? # take a reading from the onboard sensors enviro.logging.debug(f"> taking new reading") - reading = enviro.get_sensor_readings(enviro.config) + reading = enviro.get_sensor_readings() # here you can customise the sensor readings by adding extra information # or removing readings that you don't want, for example: From 0bb6f3541ecfeb00c89ff685b81537d99b8562ee Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 16:25:30 -0500 Subject: [PATCH 11/21] Fix error --- enviro/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index c4b50f9..79a43d6 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -301,7 +301,7 @@ def get_sensor_readings(): logging.info(f" - seconds since last reading: {seconds_since_last}") - readings = get_board().get_sensor_readings(seconds_since_last, config) + readings = get_board().get_sensor_readings(seconds_since_last) readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed # write out the last time log From b54a187bdaa97480dd2ea9308c023b7dfe39c536 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 17 Jan 2023 16:29:30 -0500 Subject: [PATCH 12/21] Clean up code --- enviro/config_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enviro/config_template.py b/enviro/config_template.py index a0e09f1..3cadf7b 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -49,6 +49,6 @@ moisture_target_b = 50 moisture_target_c = 50 -# compensate for usb_power +# compensate for usb power usb_power = False usb_power_temperature_offset = 4 From e1654d902686e7878bf3edcc9f20e4ee8fe6e8a8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Thu, 19 Jan 2023 16:29:51 -0500 Subject: [PATCH 13/21] Optimize config file writing on battery power --- enviro/__init__.py | 9 +++++---- enviro/config_template.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 79a43d6..d95ec6b 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -469,10 +469,11 @@ def sleep(time_override=None): rtc.set_alarm(0, minute, hour) rtc.enable_alarm_interrupt(True) - # assume we're running on battery power - logging.debug("assume battery power in config") - config.usb_power = False - helpers.write_config(config) + # always assume we're running on battery power until we know otherwise + if config.usb_power: + logging.debug("assume battery power in config") + config.usb_power = False + helpers.write_config(config) # disable the vsys hold, causing us to turn off logging.info(" - shutting down") diff --git a/enviro/config_template.py b/enviro/config_template.py index 3cadf7b..3cede77 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -51,4 +51,4 @@ # compensate for usb power usb_power = False -usb_power_temperature_offset = 4 +usb_power_temperature_offset = 4.5 From 5a3224b5215a673e829b92d8aa7d714de6d926fa Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 24 Jan 2023 14:47:33 -0500 Subject: [PATCH 14/21] Don't use config file for usb power status --- enviro/__init__.py | 35 ++++++++++++++++++++++------------- enviro/boards/grow.py | 2 +- enviro/boards/indoor.py | 4 ++-- enviro/boards/urban.py | 2 +- enviro/boards/weather.py | 2 +- enviro/config_template.py | 1 - enviro/constants.py | 3 +++ enviro/destinations/mqtt.py | 6 ------ enviro/helpers.py | 16 ---------------- enviro/provisioning.py | 31 +++++++++++++++++++++++-------- 10 files changed, 53 insertions(+), 49 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 856a42e..da230de 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -351,7 +351,7 @@ def get_sensor_readings(): logging.info(f" - seconds since last reading: {seconds_since_last}") - readings = get_board().get_sensor_readings(seconds_since_last) + readings = get_board().get_sensor_readings(seconds_since_last, vbus_present) # readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed # write out the last time log @@ -473,6 +473,8 @@ def startup(): # get the reason we were woken up reason = get_wake_reason() + add_missing_config_settings() + # give each board a chance to perform any startup it needs # =========================================================================== board = get_board() @@ -509,6 +511,25 @@ def startup(): # Note, this *may* result in a missed reading if reason == WAKE_REASON_RTC_ALARM: sleep() + + +def add_missing_config_settings(): + # check if ca file paramter is set, if not set it to not use SSL by setting to None + try: + config.mqtt_broker_ca_file + except AttributeError: + warn_missing_config_setting("mqtt_broker_ca_file") + config.mqtt_broker_ca_file = None + + try: + config.usb_power_temperature_offset + except AttributeError: + warn_missing_config_setting("usb_power_temperature_offset") + config.usb_power_temperature_offset = DEFAULT_USB_POWER_TEMPERATURE_OFFSET + +def warn_missing_config_setting(setting): + logging.warn(f" - config setting '{setting}' missing - please add it to config.py") + def sleep(time_override=None): if time_override is not None: @@ -549,12 +570,6 @@ def sleep(time_override=None): rtc.set_alarm(0, minute, hour) rtc.enable_alarm_interrupt(True) - # always assume we're running on battery power until we know otherwise - if config.usb_power: - logging.debug("assume battery power in config") - config.usb_power = False - helpers.write_config(config) - # disable the vsys hold, causing us to turn off logging.info(" - shutting down") hold_vsys_en_pin.init(Pin.IN) @@ -563,12 +578,6 @@ def sleep(time_override=None): # case we can't (and don't need to) sleep. stop_activity_led() - # indicate that we're running on usb power - which requires temperature - # and humidity adjustments. - logging.debug("switching config to usb power") - config.usb_power = True - helpers.write_config(config) - # if running via mpremote/pyboard.py with a remote mount then we can't # reset the board so just exist if phew.remote_mount: diff --git a/enviro/boards/grow.py b/enviro/boards/grow.py index cb0e081..8a16087 100644 --- a/enviro/boards/grow.py +++ b/enviro/boards/grow.py @@ -98,7 +98,7 @@ def water(moisture_levels): drip_noise() time.sleep(0.5) -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, is_usb_power): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/indoor.py b/enviro/boards/indoor.py index fa11239..675c13c 100644 --- a/enviro/boards/indoor.py +++ b/enviro/boards/indoor.py @@ -42,7 +42,7 @@ def colour_temperature_from_rgbc(r, g, b, c): ct = 10000 return round(ct) -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, is_usb_power): data = bme688.read() temperature = round(data[0], 2) @@ -50,7 +50,7 @@ def get_sensor_readings(seconds_since_last): # Compensate for additional heating when on usb power - this also changes the # relative humidity value. - if config.usb_power: + if is_usb_power: adjusted_temperature = temperature - config.usb_power_temperature_offset absolute_humidity = helpers.relative_to_absolute_humidity(humidity, temperature) humidity = helpers.absolute_to_relative_humidity(absolute_humidity, adjusted_temperature) diff --git a/enviro/boards/urban.py b/enviro/boards/urban.py index 6f5a07e..acc9303 100644 --- a/enviro/boards/urban.py +++ b/enviro/boards/urban.py @@ -34,7 +34,7 @@ def particulates(particulate_data, measure): multiplier = 10 if measure >= PM0_3_PER_LITRE else 1 return ((particulate_data[measure * 2] << 8) | particulate_data[measure * 2 + 1]) * multiplier -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, is_usb_power): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/boards/weather.py b/enviro/boards/weather.py index 3fc4b8e..9b44e13 100644 --- a/enviro/boards/weather.py +++ b/enviro/boards/weather.py @@ -180,7 +180,7 @@ def rainfall(seconds_since_last): return amount, per_second -def get_sensor_readings(seconds_since_last): +def get_sensor_readings(seconds_since_last, is_usb_power): # bme280 returns the register contents immediately and then starts a new reading # we want the current reading so do a dummy read to discard register contents first bme280.read() diff --git a/enviro/config_template.py b/enviro/config_template.py index aebef37..a345cc0 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -53,5 +53,4 @@ moisture_target_c = 50 # compensate for usb power -usb_power = False usb_power_temperature_offset = 4.5 diff --git a/enviro/constants.py b/enviro/constants.py index c4ea36a..99081ca 100644 --- a/enviro/constants.py +++ b/enviro/constants.py @@ -47,3 +47,6 @@ WATER_VAPOR_SPECIFIC_GAS_CONSTANT = 461.5 CRITICAL_WATER_TEMPERATURE = 647.096 CRITICAL_WATER_PRESSURE = 22064000 + +# default values +DEFAULT_USB_POWER_TEMPERATURE_OFFSET = 4.5 diff --git a/enviro/destinations/mqtt.py b/enviro/destinations/mqtt.py index 414fa7b..26bde1c 100644 --- a/enviro/destinations/mqtt.py +++ b/enviro/destinations/mqtt.py @@ -13,12 +13,6 @@ def upload_reading(reading): password = config.mqtt_broker_password nickname = reading["nickname"] - # check if ca file paramter is set, if not set it to not use SSL by setting to None - try: - config.mqtt_broker_ca_file - except AttributeError: - config.mqtt_broker_ca_file = None - try: if config.mqtt_broker_ca_file: # Using SSL diff --git a/enviro/helpers.py b/enviro/helpers.py index ce67f25..f2bc0c4 100644 --- a/enviro/helpers.py +++ b/enviro/helpers.py @@ -58,22 +58,6 @@ def copy_file(source, target): break outfile.write(chunk) -def write_config(config): - lines = [] - with open("config.py", "r") as infile: - lines = infile.read().split("\n") - - for i in range(0, len(lines)): - line = lines[i] - parts = line.split("=", 1) - if len(parts) == 2: - key = parts[0].strip() - if hasattr(config, key): - value = getattr(config, key) - lines[i] = f"{key} = {repr(value)}" - - with open("config.py", "w") as outfile: - outfile.write("\n".join(lines)) # temperature and humidity helpers # =========================================================================== diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 9be79f7..6cb7fff 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -12,6 +12,23 @@ if not helpers.file_exists("config.py"): helpers.copy_file("enviro/config_template.py", "config.py") +def write_config(): + lines = [] + with open("config.py", "r") as infile: + lines = infile.read().split("\n") + + for i in range(0, len(lines)): + line = lines[i] + parts = line.split("=", 1) + if len(parts) == 2: + key = parts[0].strip() + if hasattr(config, key): + value = getattr(config, key) + lines[i] = f"{key} = {repr(value)}" + + with open("config.py", "w") as outfile: + outfile.write("\n".join(lines)) + import config @@ -33,7 +50,6 @@ dns.run_catchall(ap.ifconfig()[0]) logging.info("> creating web server...") - # TODO This did not seem to work for me... @server.route("/wrong-host-redirect", methods=["GET"]) def wrong_host_redirect(request): @@ -42,7 +58,6 @@ def wrong_host_redirect(request): body = f"" return body - @server.route("/provision-welcome", methods=["GET"]) def provision_welcome(request): response = render_template("enviro/html/welcome.html", board=model) @@ -53,7 +68,7 @@ def provision_welcome(request): def provision_step_1_nickname(request): if request.method == "POST": config.nickname = request.form["nickname"] - helpers.write_config(config) + write_config() return redirect(f"http://{DOMAIN}/provision-step-2-wifi") else: return render_template("enviro/html/provision-step-1-nickname.html", board=model) @@ -64,7 +79,7 @@ def provision_step_2_wifi(request): if request.method == "POST": config.wifi_ssid = request.form["wifi_ssid"] config.wifi_password = request.form["wifi_password"] - helpers.write_config(config) + write_config() return redirect(f"http://{DOMAIN}/provision-step-3-logging") else: return render_template("enviro/html/provision-step-2-wifi.html", board=model) @@ -75,7 +90,7 @@ def provision_step_3_logging(request): if request.method == "POST": config.reading_frequency = int(request.form["reading_frequency"]) config.upload_frequency = int(request.form["upload_frequency"]) if request.form["upload_frequency"] else None - helpers.write_config(config) + write_config() return redirect(f"http://{DOMAIN}/provision-step-4-destination") else: return render_template("enviro/html/provision-step-3-logging.html", board=model) @@ -106,7 +121,7 @@ def provision_step_4_destination(request): config.influxdb_token = request.form["influxdb_token"] config.influxdb_bucket = request.form["influxdb_bucket"] - helpers.write_config(config) + write_config() if model == "grow": return redirect(f"http://{DOMAIN}/provision-step-grow-sensors") @@ -135,7 +150,7 @@ def provision_step_grow_sensors(request): except ValueError: pass - helpers.write_config(config) + write_config() return redirect(f"http://{DOMAIN}/provision-step-5-done") else: @@ -145,7 +160,7 @@ def provision_step_grow_sensors(request): @server.route("/provision-step-5-done", methods=["GET", "POST"]) def provision_step_5_done(request): config.provisioned = True - helpers.write_config(config) + write_config() # a post request to the done handler means we're finished and # should reset the board From 7d5ed7d55ab836382d2e33275a024feda6d1b4f5 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 24 Jan 2023 15:11:44 -0500 Subject: [PATCH 15/21] Clean up code --- enviro/__init__.py | 2 -- enviro/provisioning.py | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index da230de..780d758 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -511,7 +511,6 @@ def startup(): # Note, this *may* result in a missed reading if reason == WAKE_REASON_RTC_ALARM: sleep() - def add_missing_config_settings(): # check if ca file paramter is set, if not set it to not use SSL by setting to None @@ -530,7 +529,6 @@ def add_missing_config_settings(): def warn_missing_config_setting(setting): logging.warn(f" - config setting '{setting}' missing - please add it to config.py") - def sleep(time_override=None): if time_override is not None: logging.info(f"> going to sleep for {time_override} minute(s)") diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 6cb7fff..3f5c630 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -12,6 +12,7 @@ if not helpers.file_exists("config.py"): helpers.copy_file("enviro/config_template.py", "config.py") +# write the current values in config to the config.py file def write_config(): lines = [] with open("config.py", "r") as infile: From 9a356fafa16382362fd6933e30cdb5456f400588 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 24 Jan 2023 15:22:30 -0500 Subject: [PATCH 16/21] Cleanup code --- enviro/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/enviro/helpers.py b/enviro/helpers.py index f2bc0c4..1503ad4 100644 --- a/enviro/helpers.py +++ b/enviro/helpers.py @@ -58,7 +58,6 @@ def copy_file(source, target): break outfile.write(chunk) - # temperature and humidity helpers # =========================================================================== From dae734fed980132e0599fd23269bd0c499027092 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 24 Jan 2023 17:39:07 -0500 Subject: [PATCH 17/21] More code cleanup --- enviro/provisioning.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 3f5c630..24ab3fa 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -51,6 +51,7 @@ def write_config(): dns.run_catchall(ap.ifconfig()[0]) logging.info("> creating web server...") + # TODO This did not seem to work for me... @server.route("/wrong-host-redirect", methods=["GET"]) def wrong_host_redirect(request): @@ -59,6 +60,7 @@ def wrong_host_redirect(request): body = f"" return body + @server.route("/provision-welcome", methods=["GET"]) def provision_welcome(request): response = render_template("enviro/html/welcome.html", board=model) From 67c12e9b95833fa7e44abd4293356ef43f8d4173 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Sun, 29 Jan 2023 09:04:33 -0500 Subject: [PATCH 18/21] Remove unnecessary changes --- enviro/provisioning.py | 2 +- main.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/enviro/provisioning.py b/enviro/provisioning.py index 24ab3fa..1baaef2 100644 --- a/enviro/provisioning.py +++ b/enviro/provisioning.py @@ -207,4 +207,4 @@ def catchall(request): logging.info(" - client connected!", ap.status("stations")[0]) logging.info("> running provisioning application...") -server.run(host="0.0.0.0", port=80) +server.run(host="0.0.0.0", port=80) \ No newline at end of file diff --git a/main.py b/main.py index de938bb..95eff3b 100644 --- a/main.py +++ b/main.py @@ -73,9 +73,9 @@ # here you can customise the sensor readings by adding extra information # or removing readings that you don't want, for example: # - # del reading["temperature"] # remove the temperature reading + # del readings["temperature"] # remove the temperature reading # - # reading["custom"] = my_reading() # add my custom reading value + # readings["custom"] = my_reading() # add my custom reading value # is an upload destination set? if enviro.config.destination: From 321239c6083b3e0ed39aa04ec69c1f3956dfdd3d Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 31 Jan 2023 14:38:28 -0500 Subject: [PATCH 19/21] Move config adjustments earlier --- enviro/__init__.py | 21 +++------------------ enviro/config_defaults.py | 23 +++++++++++++++++++++++ enviro/constants.py | 3 --- 3 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 enviro/config_defaults.py diff --git a/enviro/__init__.py b/enviro/__init__.py index 780d758..7e5f509 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -97,8 +97,11 @@ def stop_activity_led(): from machine import RTC, ADC import phew from pcf85063a import PCF85063A +import enviro.config_defaults as config_defaults import enviro.helpers as helpers +config_defaults.add_missing_config_settings() + # read the state of vbus to know if we were woken up by USB vbus_present = Pin("WL_GPIO2", Pin.IN).value() @@ -473,8 +476,6 @@ def startup(): # get the reason we were woken up reason = get_wake_reason() - add_missing_config_settings() - # give each board a chance to perform any startup it needs # =========================================================================== board = get_board() @@ -512,22 +513,6 @@ def startup(): if reason == WAKE_REASON_RTC_ALARM: sleep() -def add_missing_config_settings(): - # check if ca file paramter is set, if not set it to not use SSL by setting to None - try: - config.mqtt_broker_ca_file - except AttributeError: - warn_missing_config_setting("mqtt_broker_ca_file") - config.mqtt_broker_ca_file = None - - try: - config.usb_power_temperature_offset - except AttributeError: - warn_missing_config_setting("usb_power_temperature_offset") - config.usb_power_temperature_offset = DEFAULT_USB_POWER_TEMPERATURE_OFFSET - -def warn_missing_config_setting(setting): - logging.warn(f" - config setting '{setting}' missing - please add it to config.py") def sleep(time_override=None): if time_override is not None: diff --git a/enviro/config_defaults.py b/enviro/config_defaults.py new file mode 100644 index 0000000..2b1f5b6 --- /dev/null +++ b/enviro/config_defaults.py @@ -0,0 +1,23 @@ +import config +from phew import logging + +DEFAULT_USB_POWER_TEMPERATURE_OFFSET = 4.5 + + +def add_missing_config_settings(): + try: + # check if ca file parameter is set, if not set it to not use SSL by setting to None + config.mqtt_broker_ca_file + except AttributeError: + warn_missing_config_setting("mqtt_broker_ca_file") + config.mqtt_broker_ca_file = None + + try: + config.usb_power_temperature_offset + except AttributeError: + warn_missing_config_setting("usb_power_temperature_offset") + config.usb_power_temperature_offset = DEFAULT_USB_POWER_TEMPERATURE_OFFSET + + +def warn_missing_config_setting(setting): + logging.warn(f" - config setting '{setting}' missing, please add it to config.py") diff --git a/enviro/constants.py b/enviro/constants.py index 99081ca..c4ea36a 100644 --- a/enviro/constants.py +++ b/enviro/constants.py @@ -47,6 +47,3 @@ WATER_VAPOR_SPECIFIC_GAS_CONSTANT = 461.5 CRITICAL_WATER_TEMPERATURE = 647.096 CRITICAL_WATER_PRESSURE = 22064000 - -# default values -DEFAULT_USB_POWER_TEMPERATURE_OFFSET = 4.5 From 737176bfa79ae12d76f799a60e649b10502d2311 Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 31 Jan 2023 14:41:34 -0500 Subject: [PATCH 20/21] Fix log indent --- enviro/config_defaults.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enviro/config_defaults.py b/enviro/config_defaults.py index 2b1f5b6..cfdf5dd 100644 --- a/enviro/config_defaults.py +++ b/enviro/config_defaults.py @@ -20,4 +20,4 @@ def add_missing_config_settings(): def warn_missing_config_setting(setting): - logging.warn(f" - config setting '{setting}' missing, please add it to config.py") + logging.warn(f"> config setting '{setting}' missing, please add it to config.py") From 1583bee11581a11bb1058206f44497cf998a488a Mon Sep 17 00:00:00 2001 From: Mike Cifelli <1836280-mike-cifelli@users.noreply.gitlab.com> Date: Tue, 31 Jan 2023 14:53:31 -0500 Subject: [PATCH 21/21] Clean up code --- enviro/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 7e5f509..236f280 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -513,7 +513,6 @@ def startup(): if reason == WAKE_REASON_RTC_ALARM: sleep() - def sleep(time_override=None): if time_override is not None: logging.info(f"> going to sleep for {time_override} minute(s)")