Added voltage check for all Pow* devices

This commit is contained in:
Gunnar Skjold
2024-05-23 19:40:28 +02:00
parent faa468b287
commit a137316cec

View File

@@ -701,12 +701,10 @@ void loop() {
#endif #endif
handleUiLanguage(); handleUiLanguage();
} }
/*
if(now - lastVoltageCheck > 500) { if(now - lastVoltageCheck > 500) {
handleVoltageCheck(); handleVoltageCheck();
lastVoltageCheck = now; lastVoltageCheck = now;
} }
*/
} else { } else {
if(WiFi.smartConfigDone()) { if(WiFi.smartConfigDone()) {
debugI_P(PSTR("Smart config DONE!")); debugI_P(PSTR("Smart config DONE!"));
@@ -989,23 +987,23 @@ void handleSystem(unsigned long now) {
} }
#endif #endif
} }
handleVoltageCheck();
} }
bool handleVoltageCheck() { bool handleVoltageCheck() {
if(sysConfig.boardType == 7 && maxVcc > 2.8) { // Pow-U if(sysConfig.boardType >= 5 && sysConfig.boardType <= 7 && maxVcc > 2.8) { // Pow-*
float vcc = hw.getVcc(); float vcc = hw.getVcc();
if(vcc > 3.4 || vcc < 2.8) { if(vcc > 3.4 || vcc < 2.8) {
maxVcc = 0; maxVcc = 0;
} else if(vcc > maxVcc) { } else if(vcc > maxVcc) {
debugD_P(PSTR("Setting new max Vcc to %.2f"), vcc); debugD_P(PSTR("Setting new max Vcc to %.2f"), vcc);
maxVcc = vcc; maxVcc = vcc;
} else if(WiFi.getMode() != WIFI_OFF) { } else {
float diff = min(maxVcc, (float) 3.3)-vcc; float diff = min(maxVcc, (float) 3.3)-vcc;
if(diff > 0.4) { if(diff > 0.4) {
debugW_P(PSTR("Vcc dropped to %.2f, disconnecting WiFi for 5 seconds to preserve power"), vcc); if(WiFi.getMode() == WIFI_STA) {
ch->disconnect(5000); debugW_P(PSTR("Vcc dropped to %.2f, disconnecting WiFi for 5 seconds to preserve power"), vcc);
ch->disconnect(5000);
}
return false; return false;
} }
} }
@@ -1140,7 +1138,14 @@ void errorBlink() {
} }
} }
unsigned long lastConnectRetry = 0;
void connectToNetwork() { void connectToNetwork() {
if(lastConnectRetry > 0 && (millis() - lastConnectRetry) < 10000) {
delay(50);
return;
}
lastConnectRetry = millis();
if(!handleVoltageCheck()) { if(!handleVoltageCheck()) {
debugW_P(PSTR("Voltage is not high enough to reconnect")); debugW_P(PSTR("Voltage is not high enough to reconnect"));
return; return;