diff --git a/data/igate_conf.json b/data/igate_conf.json index 7cd5642..a0b68d7 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -52,7 +52,7 @@ "sendExternalVoltage": false, "externalVoltagePin": 34, "monitorExternalVoltage": false, - "externalSleepVoltage": 3.0 + "externalSleepVoltage": 10.9 }, "bme": { "active": false, diff --git a/data_embed/index.html b/data_embed/index.html index f9cc911..7414a25 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -982,7 +982,7 @@ class="form-control" step="0.1" min="3.0" - max="4.2" + max="3.7" /> volts receivedPackets; @@ -185,5 +185,5 @@ void loop() { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); Utils::checkRebootTime(); - Utils::checkSleepByLowBatteryVoltage(); + Utils::checkSleepByLowBatteryVoltage(1); } \ No newline at end of file diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index 0ceebf1..bc44580 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -1,9 +1,11 @@ #include "battery_utils.h" #include "configuration.h" #include "boards_pinout.h" +#include "utils.h" extern Configuration Config; extern uint32_t lastBatteryCheck; +extern bool shouldSleepLowVoltage; float adcReadingTransformation = (3.3/4095); float voltageDividerCorrection = 0.288; @@ -88,4 +90,18 @@ namespace BATTERY_Utils { } } + void startupBatteryHealth() { + #ifdef BATTERY_PIN + if (Config.battery.monitorInternalVoltage && checkInternalVoltage() < Config.battery.internalSleepVoltage) { + shouldSleepLowVoltage = true; + } + #endif + if (Config.battery.monitorExternalVoltage && checkExternalVoltage() < Config.battery.externalSleepVoltage) { + shouldSleepLowVoltage = true; + } + if (shouldSleepLowVoltage) { + Utils::checkSleepByLowBatteryVoltage(0); + } + } + } \ No newline at end of file diff --git a/src/battery_utils.h b/src/battery_utils.h index 697a471..4bc0dd9 100644 --- a/src/battery_utils.h +++ b/src/battery_utils.h @@ -8,7 +8,8 @@ namespace BATTERY_Utils { float checkInternalVoltage(); float checkExternalVoltage(); - void checkIfShouldSleep(); + void checkIfShouldSleep(); // ???? + void startupBatteryHealth(); } diff --git a/src/power_utils.cpp b/src/power_utils.cpp index 0de8dba..2037238 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -1,4 +1,5 @@ #include "configuration.h" +#include "battery_utils.h" #include "boards_pinout.h" #include "power_utils.h" @@ -128,7 +129,7 @@ namespace POWER_Utils { pinMode(INTERNAL_LED_PIN, OUTPUT); #endif - if (Config.battery.sendExternalVoltage) { + if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) { pinMode(Config.battery.externalVoltagePin, INPUT); } @@ -152,6 +153,8 @@ namespace POWER_Utils { #endif delay(1000); + + BATTERY_Utils::startupBatteryHealth(); } } \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index a5e3487..f5822fd 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -32,7 +32,7 @@ extern String distance; extern bool WiFiConnected; extern int wxModuleType; extern bool backUpDigiMode; -extern bool shouldSleep; +extern bool shouldSleepLowVoltage; bool statusAfterBoot = true; bool beaconUpdate = true; @@ -123,12 +123,19 @@ namespace Utils { secondaryBeaconPacket += Config.beacon.comment; #ifdef BATTERY_PIN - if (Config.battery.sendInternalVoltage) { + if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) { float internalVoltage = BATTERY_Utils::checkInternalVoltage(); - String internalVoltageInfo = "Batt=" + String(internalVoltage,2) + "V"; - beaconPacket += " " + internalVoltageInfo; - secondaryBeaconPacket += " " + internalVoltageInfo; - sixthLine = " ( " + internalVoltageInfo + ")"; + String internalVoltageInfo = String(internalVoltage,2) + "V"; + if (Config.battery.sendInternalVoltage) { + beaconPacket += " Batt=" + internalVoltageInfo; + secondaryBeaconPacket += " Batt=" + internalVoltageInfo; + sixthLine = " (Batt=" + internalVoltageInfo + ")"; + } + if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) { + beaconPacket += " **IntBatWarning:SLEEP**"; + secondaryBeaconPacket += " **IntBatWarning:SLEEP**"; + shouldSleepLowVoltage = true; + } } #endif @@ -140,10 +147,10 @@ namespace Utils { secondaryBeaconPacket += " Ext=" + externalVoltageInfo; sixthLine = " (Ext V=" + externalVoltageInfo + ")"; } - if (Config.battery.monitorExternalVoltage && externalVoltage <= Config.battery.externalSleepVoltage) { + if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) { beaconPacket += " **ExtBatWarning:SLEEP**"; secondaryBeaconPacket += " **ExtBatWarning:SLEEP**"; - shouldSleep = true; + shouldSleepLowVoltage = true; } } @@ -272,11 +279,22 @@ namespace Utils { } } - void checkSleepByLowBatteryVoltage() { - if (shouldSleep) { - // dormir - shouldSleep = false; - Serial.println("Durmiendo"); + void checkSleepByLowBatteryVoltage(uint8_t mode) { + if (shouldSleepLowVoltage) { + if (mode == 0) { + delay(3000); + } + Serial.println("\n\n*** Sleeping Low Battey Voltage ***\n\n"); + esp_sleep_enable_timer_wakeup(30 * 60 * 1000000); // sleep 30 min + if (mode == 1) { + display_toggle(false); + } + #ifdef VEXT_CTRL + #ifndef HELTEC_WSL_V3 + digitalWrite(VEXT_CTRL, LOW); + #endif + #endif + esp_deep_sleep_start(); } } diff --git a/src/utils.h b/src/utils.h index b8491f6..d25d7eb 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,7 +25,7 @@ namespace Utils { void println(const String& text); void checkRebootMode(); void checkRebootTime(); - void checkSleepByLowBatteryVoltage(); + void checkSleepByLowBatteryVoltage(uint8_t mode); } diff --git a/src/web_utils.cpp b/src/web_utils.cpp index 5ff83ad..3b7616d 100644 --- a/src/web_utils.cpp +++ b/src/web_utils.cpp @@ -2,6 +2,7 @@ #include "configuration.h" #include "ota_utils.h" #include "web_utils.h" +#include "display.h" #include "utils.h" extern Configuration Config; @@ -192,7 +193,7 @@ namespace WEB_Utils { AsyncWebServerResponse *response = request->beginResponse(302, "text/html", ""); response->addHeader("Location", "/"); request->send(response); - + display_toggle(false); ESP.restart(); } @@ -204,6 +205,7 @@ namespace WEB_Utils { request->send(200, "text/plain", "Beacon will be sent in a while"); } else if (type == "reboot") { + display_toggle(false); ESP.restart(); } else { request->send(404, "text/plain", "Not Found");