full update for BatteryHealthMonitor
This commit is contained in:
parent
c6687529da
commit
3589f54d02
|
|
@ -52,7 +52,7 @@
|
||||||
"sendExternalVoltage": false,
|
"sendExternalVoltage": false,
|
||||||
"externalVoltagePin": 34,
|
"externalVoltagePin": 34,
|
||||||
"monitorExternalVoltage": false,
|
"monitorExternalVoltage": false,
|
||||||
"externalSleepVoltage": 3.0
|
"externalSleepVoltage": 10.9
|
||||||
},
|
},
|
||||||
"bme": {
|
"bme": {
|
||||||
"active": false,
|
"active": false,
|
||||||
|
|
|
||||||
|
|
@ -982,7 +982,7 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
step="0.1"
|
step="0.1"
|
||||||
min="3.0"
|
min="3.0"
|
||||||
max="4.2"
|
max="3.7"
|
||||||
/>
|
/>
|
||||||
<span class="input-group-text"
|
<span class="input-group-text"
|
||||||
>volts</span
|
>volts</span
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ String batteryVoltage; // ????
|
||||||
bool backUpDigiMode = false;
|
bool backUpDigiMode = false;
|
||||||
bool modemLoggedToAPRSIS = false;
|
bool modemLoggedToAPRSIS = false;
|
||||||
|
|
||||||
bool shouldSleep = false;
|
bool shouldSleepLowVoltage = false;
|
||||||
|
|
||||||
std::vector<ReceivedPacket> receivedPackets;
|
std::vector<ReceivedPacket> receivedPackets;
|
||||||
|
|
||||||
|
|
@ -185,5 +185,5 @@ void loop() {
|
||||||
|
|
||||||
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||||
Utils::checkRebootTime();
|
Utils::checkRebootTime();
|
||||||
Utils::checkSleepByLowBatteryVoltage();
|
Utils::checkSleepByLowBatteryVoltage(1);
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
#include "battery_utils.h"
|
#include "battery_utils.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "boards_pinout.h"
|
#include "boards_pinout.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
extern Configuration Config;
|
extern Configuration Config;
|
||||||
extern uint32_t lastBatteryCheck;
|
extern uint32_t lastBatteryCheck;
|
||||||
|
extern bool shouldSleepLowVoltage;
|
||||||
|
|
||||||
float adcReadingTransformation = (3.3/4095);
|
float adcReadingTransformation = (3.3/4095);
|
||||||
float voltageDividerCorrection = 0.288;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,8 @@ namespace BATTERY_Utils {
|
||||||
|
|
||||||
float checkInternalVoltage();
|
float checkInternalVoltage();
|
||||||
float checkExternalVoltage();
|
float checkExternalVoltage();
|
||||||
void checkIfShouldSleep();
|
void checkIfShouldSleep(); // ????
|
||||||
|
void startupBatteryHealth();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "battery_utils.h"
|
||||||
#include "boards_pinout.h"
|
#include "boards_pinout.h"
|
||||||
#include "power_utils.h"
|
#include "power_utils.h"
|
||||||
|
|
||||||
|
|
@ -128,7 +129,7 @@ namespace POWER_Utils {
|
||||||
pinMode(INTERNAL_LED_PIN, OUTPUT);
|
pinMode(INTERNAL_LED_PIN, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Config.battery.sendExternalVoltage) {
|
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
|
||||||
pinMode(Config.battery.externalVoltagePin, INPUT);
|
pinMode(Config.battery.externalVoltagePin, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,6 +153,8 @@ namespace POWER_Utils {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
|
BATTERY_Utils::startupBatteryHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ extern String distance;
|
||||||
extern bool WiFiConnected;
|
extern bool WiFiConnected;
|
||||||
extern int wxModuleType;
|
extern int wxModuleType;
|
||||||
extern bool backUpDigiMode;
|
extern bool backUpDigiMode;
|
||||||
extern bool shouldSleep;
|
extern bool shouldSleepLowVoltage;
|
||||||
|
|
||||||
bool statusAfterBoot = true;
|
bool statusAfterBoot = true;
|
||||||
bool beaconUpdate = true;
|
bool beaconUpdate = true;
|
||||||
|
|
@ -123,12 +123,19 @@ namespace Utils {
|
||||||
secondaryBeaconPacket += Config.beacon.comment;
|
secondaryBeaconPacket += Config.beacon.comment;
|
||||||
|
|
||||||
#ifdef BATTERY_PIN
|
#ifdef BATTERY_PIN
|
||||||
if (Config.battery.sendInternalVoltage) {
|
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
|
||||||
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
|
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
|
||||||
String internalVoltageInfo = "Batt=" + String(internalVoltage,2) + "V";
|
String internalVoltageInfo = String(internalVoltage,2) + "V";
|
||||||
beaconPacket += " " + internalVoltageInfo;
|
if (Config.battery.sendInternalVoltage) {
|
||||||
secondaryBeaconPacket += " " + internalVoltageInfo;
|
beaconPacket += " Batt=" + internalVoltageInfo;
|
||||||
sixthLine = " ( " + internalVoltageInfo + ")";
|
secondaryBeaconPacket += " Batt=" + internalVoltageInfo;
|
||||||
|
sixthLine = " (Batt=" + internalVoltageInfo + ")";
|
||||||
|
}
|
||||||
|
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
|
||||||
|
beaconPacket += " **IntBatWarning:SLEEP**";
|
||||||
|
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
|
||||||
|
shouldSleepLowVoltage = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -140,10 +147,10 @@ namespace Utils {
|
||||||
secondaryBeaconPacket += " Ext=" + externalVoltageInfo;
|
secondaryBeaconPacket += " Ext=" + externalVoltageInfo;
|
||||||
sixthLine = " (Ext V=" + externalVoltageInfo + ")";
|
sixthLine = " (Ext V=" + externalVoltageInfo + ")";
|
||||||
}
|
}
|
||||||
if (Config.battery.monitorExternalVoltage && externalVoltage <= Config.battery.externalSleepVoltage) {
|
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
|
||||||
beaconPacket += " **ExtBatWarning:SLEEP**";
|
beaconPacket += " **ExtBatWarning:SLEEP**";
|
||||||
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
|
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
|
||||||
shouldSleep = true;
|
shouldSleepLowVoltage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,11 +279,22 @@ namespace Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkSleepByLowBatteryVoltage() {
|
void checkSleepByLowBatteryVoltage(uint8_t mode) {
|
||||||
if (shouldSleep) {
|
if (shouldSleepLowVoltage) {
|
||||||
// dormir
|
if (mode == 0) {
|
||||||
shouldSleep = false;
|
delay(3000);
|
||||||
Serial.println("Durmiendo");
|
}
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Utils {
|
||||||
void println(const String& text);
|
void println(const String& text);
|
||||||
void checkRebootMode();
|
void checkRebootMode();
|
||||||
void checkRebootTime();
|
void checkRebootTime();
|
||||||
void checkSleepByLowBatteryVoltage();
|
void checkSleepByLowBatteryVoltage(uint8_t mode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "ota_utils.h"
|
#include "ota_utils.h"
|
||||||
#include "web_utils.h"
|
#include "web_utils.h"
|
||||||
|
#include "display.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
extern Configuration Config;
|
extern Configuration Config;
|
||||||
|
|
@ -192,7 +193,7 @@ namespace WEB_Utils {
|
||||||
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
|
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
|
||||||
response->addHeader("Location", "/");
|
response->addHeader("Location", "/");
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
display_toggle(false);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,6 +205,7 @@ namespace WEB_Utils {
|
||||||
|
|
||||||
request->send(200, "text/plain", "Beacon will be sent in a while");
|
request->send(200, "text/plain", "Beacon will be sent in a while");
|
||||||
} else if (type == "reboot") {
|
} else if (type == "reboot") {
|
||||||
|
display_toggle(false);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
} else {
|
} else {
|
||||||
request->send(404, "text/plain", "Not Found");
|
request->send(404, "text/plain", "Not Found");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue