diff --git a/README.md b/README.md index dcbf032..5d56b02 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ wget -O - https://raw.githubusercontent.com/Eagleshot/GlacierCam/main/updateScri ## Software - [ ] Automatically set camera to reboot when power is on again - [ ] Add log level settings -- [ ] Improved settings validation +- [X] Improved settings validation - [x] Code review by Philip - [x] Improve the format of saved data -> e.g. use .yaml instead of a csv file so additional data can easily be added or different data versions can be used in future software - [ ] Enable watchdog diff --git a/main.py b/main.py index 9d0aaa2..a08abec 100644 --- a/main.py +++ b/main.py @@ -264,14 +264,13 @@ def get_cpu_serial(): ########################### # Set voltage thresholds ########################### - try: # If settings low voltage threshold exists - if 2.0 <= settings.get("low_voltage_threshold") <= 25.0 or settings.get("low_voltage_threshold") == 0: + if settings.get("low_voltage_threshold"): wittyPi.set_low_voltage_threshold(settings.get("low_voltage_threshold")) # If settings recovery voltage threshold exists - if 2.0 <= settings.get("recovery_voltage_threshold") <= 25.0 or settings.get("recovery_voltage_threshold") == 0: + if settings.get("recovery_voltage_threshold"): # Recovery voltage threshold must be equal or greater than low voltage threshold if settings.get("recovery_voltage_threshold") < settings.get("low_voltage_threshold"): settings.set("recovery_voltage_threshold", settings.get("low_voltage_threshold")) @@ -340,17 +339,13 @@ def get_cpu_serial(): logging.warning("Could not append new measurements to log: %s", str(e)) ########################### -# Upload diagnostics data +# Upload extended diagnostics data ########################### try: - # fileserver.append_file("diagnostics.csv", "", FILE_PATH) - # Upload WittyPi diagnostics if settings.get("uploadWittyPiDiagnostics") and CONNECTED_TO_SERVER: - - fileserver.append_file("wittyPi.log", f"{FILE_PATH}wittypi/") # Witty Pi log - fileserver.append_file("schedule.log", f"{FILE_PATH}wittypi/") # Witty Pi schedule - + fileserver.append_file("wittyPi.log", f"{FILE_PATH}wittypi/") + fileserver.append_file("schedule.log", f"{FILE_PATH}wittypi/") except Exception as e: logging.warning("Could not upload diagnostics data: %s", str(e)) diff --git a/witty_pi_4.py b/witty_pi_4.py index fb4698b..5f722b7 100644 --- a/witty_pi_4.py +++ b/witty_pi_4.py @@ -118,12 +118,17 @@ def get_recovery_voltage_threshold(self) -> float: def set_low_voltage_threshold(self, voltage: float) -> float: '''Sets the low voltage threshold from the Witty Pi 4''' try: - if voltage != self.get_low_voltage_threshold(): - low_voltage_threshold = self.run_command(f"set_low_voltage_threshold {int(voltage*10)}") - logging.info("Set low voltage threshold to: %s V", voltage) - return low_voltage_threshold + if 2.0 <= voltage <= 25.0 or voltage == 0: + if voltage != self.get_low_voltage_threshold(): + low_voltage_threshold = self.run_command(f"set_low_voltage_threshold {int(voltage*10)}") + logging.info("Set low voltage threshold to: %s V", voltage) + return low_voltage_threshold + + logging.info("Low voltage threshold already set to: %s V", voltage) + + else: + logging.error("Voltage must be between 2.0 and 25.0 V (or 0 to disable).") - logging.info("Low voltage threshold already set to: %s V", voltage) return voltage except Exception as e: @@ -134,12 +139,17 @@ def set_low_voltage_threshold(self, voltage: float) -> float: def set_recovery_voltage_threshold(self, voltage: float) -> float: '''Sets the recovery voltage threshold from the Witty Pi 4''' try: - if voltage != self.get_recovery_voltage_threshold(): - recovery_voltage_threshold = self.run_command(f"set_recovery_voltage_threshold {int(voltage*10)}") - logging.info("Set recovery voltage threshold to: %s V", voltage) - return recovery_voltage_threshold + if 2.0 <= voltage <= 25.0 or voltage == 0: + if voltage != self.get_recovery_voltage_threshold(): + recovery_voltage_threshold = self.run_command(f"set_recovery_voltage_threshold {int(voltage*10)}") + logging.info("Set recovery voltage threshold to: %s V", voltage) + return recovery_voltage_threshold + + logging.info("Recovery voltage threshold already set to: %s V", voltage) - logging.info("Recovery voltage threshold already set to: %s V", voltage) + else: + logging.error("Voltage must be between 2.0 and 25.0 V (or 0 to disable).") + return voltage except Exception as e: