From cbde8ee11c8e15fd61795c30c0e904f292248fa4 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 20 Apr 2024 13:39:16 +0200 Subject: [PATCH] Battery voltage below minimum should be treated as 0% --- esp32/include/ControllerConfiguration.h | 6 +++--- esp32/src/main.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index 6bbe72a..4768d39 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -127,7 +127,7 @@ #define FIRMWARE_BASENAME "PlantControl" #define FIRMWARE_NAME FIRMWARE_BASENAME FIRMWARE_FEATURE1 FIRMWARE_FEATURE2 -#define FIRMWARE_VERSIONNMUMBER "3.010" +#define FIRMWARE_VERSIONNMUMBER "3.011" #ifdef HWREVISION07 #define FIRMWARE_VERSION FIRMWARE_VERSIONNMUMBER " HW0.7" @@ -158,8 +158,8 @@ #define SOLAR_CHARGE_MAX_VOLTAGE 9 /**< Sun is shining (noon) */ #define SOLAR_MAX_VOLTAGE_POSSIBLE 100 /**< higher values are treated as not connected sensor */ #define VOLT_MAX_BATT 4.2f -#define VOLT_MIN_BATT 3.0f /**< Minimum battery voltage for normal operation */ -#define LOWVOLT_SLEEP_FACTOR 3 /**< Factor for nightsleep delay, if the battery drops below minimum (@see VOLT_MIN_BATT) */ +#define VOLT_MIN_BATT 3.2f /**< Minimum battery voltage for normal operation */ +#define LOWVOLT_SLEEP_FACTOR 6 /**< Factor for nightsleep delay, if the battery drops below minimum (@see VOLT_MIN_BATT) */ #define LOWVOLT_SLEEP_MINIMUM 7200 /**< At low voltage sleep at least for 120 minutes (two hours) */ #define WATER_LEVEL_MINIMUM 500 /**< Minimum Analog value (1023 is the maximum)*/ diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index e5124bd..c68d3a9 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -1095,7 +1095,16 @@ void plantcontrol() sensorWater.setProperty("raw").send(String(waterRawSensor.getAverage())); } } - sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT)); + + if (mBatteryVoltage < VOLT_MIN_BATT) + { + sensorLipo.setProperty("percent").send("0"); + } + else + { + sensorLipo.setProperty("percent").send(String(100 * (((mBatteryVoltage - VOLT_MIN_BATT) / (VOLT_MAX_BATT - VOLT_MIN_BATT))))); + } + sensorLipo.setProperty("volt").send(String(mBatteryVoltage)); sensorLipo.setProperty("current").send(String(battery.getCurrent())); sensorLipo.setProperty("Ah").send(String(battery.getAh()));