improvement: low voltage cut off as web ui option

This commit is contained in:
SQ2CPA 2024-03-28 18:28:31 +01:00
parent db21a08904
commit 968d9188be
8 changed files with 31 additions and 18 deletions

View file

@ -66,6 +66,7 @@
"sendBatteryVoltage": false,
"externalVoltageMeasurement": false,
"externalVoltagePin": 34,
"lowPowerMode": false
"lowPowerMode": false,
"lowVoltageCutOff": 0
}
}

View file

@ -1280,6 +1280,25 @@
>
</div>
</div>
<div class="col-12 mt-3">
<label
for="other.lowVoltageCutOff"
class="form-label"
>Low voltage cut off <small>(Deep sleep below specific voltage)</small></label
>
<input
type="text"
name="other.lowVoltageCutOff"
id="other.lowVoltageCutOff"
placeholder="0"
min="0"
step="0.01"
class="form-control"
/>
<div class="form-text">
MCU will deep sleep when below provided battery voltage to save power. Set to <strong>0</strong> if you don't want this option. <u>Please calibrate your voltage reading first!</u>
</div>
</div>
</div>
</div>
</div>

View file

@ -215,6 +215,7 @@ function loadSettings(settings) {
// Experimental
document.getElementById("other.lowPowerMode").checked = settings.other.lowPowerMode;
document.getElementById("other.lowVoltageCutOff").value = settings.other.lowVoltageCutOff || 0
updateImage();
refreshSpeedStandard();

View file

@ -154,7 +154,9 @@ void loop() {
return; // Don't process IGate and Digi during OTA update
}
BATTERY_Utils::checkIfShouldSleep();
if (Config.lowVoltageCutOff > 0) {
BATTERY_Utils::checkIfShouldSleep();
}
thirdLine = Utils::getLocalIP();

View file

@ -1,12 +1,6 @@
#include "battery_utils.h"
#include "configuration.h"
#include "pins_config.h"
//#include "lora_utils.h"
// Uncomment if you want to monitor voltage and sleep if voltage is too low (<3.15V)
//#define LOW_VOLTAGE_CUTOFF
float cutOffVoltage = 3.15;
extern Configuration Config;
extern uint32_t lastBatteryCheck;
@ -65,24 +59,15 @@ namespace BATTERY_Utils {
}
void checkIfShouldSleep() {
#ifdef LOW_VOLTAGE_CUTOFF
if (lastBatteryCheck == 0 || millis() - lastBatteryCheck >= 15 * 60 * 1000) {
lastBatteryCheck = millis();
float voltage = checkBattery();
if (voltage < cutOffVoltage) {
/* Send message over APRS-IS or over LoRa???
APRS_IS_Utils::upload("battery is low = sleeping")
LoRa_Utils::sendNewMessage("battery is low = sleeping");
*/
if (voltage < Config.lowVoltageCutOff) {
ESP.deepSleep(1800000000); // 30 min sleep (60s = 60e6)
}
}
#endif
}
}

View file

@ -97,6 +97,7 @@ void Configuration::writeFile() {
data["ota"]["password"] = ota.password;
data["other"]["lowPowerMode"] = lowPowerMode;
data["other"]["lowVoltageCutOff"] = lowVoltageCutOff;
serializeJson(data, configFile);
@ -163,6 +164,7 @@ bool Configuration::readFile() {
tnc.acceptOwn = data["tnc"]["acceptOwn"].as<bool>();
lowPowerMode = data["other"]["lowPowerMode"].as<bool>();
lowVoltageCutOff = data["other"]["lowVoltageCutOff"].as<double>();
int stationMode = data["stationMode"].as<int>(); // deprecated but need to specify config version
@ -336,6 +338,7 @@ void Configuration::init() {
externalVoltagePin = 34;
lowPowerMode = false;
lowVoltageCutOff = 0;
Serial.println("todo escrito");
}

View file

@ -115,6 +115,7 @@ public:
bool externalVoltageMeasurement;
int externalVoltagePin;
bool lowPowerMode;
double lowVoltageCutOff;
std::vector<WiFi_AP> wifiAPs;
WiFi_Auto_AP wifiAutoAP;
Beacon beacon; // new

View file

@ -156,6 +156,7 @@ namespace WEB_Utils {
}
Config.lowPowerMode = request->hasParam("other.lowPowerMode", true);
Config.lowVoltageCutOff = request->getParam("other.lowVoltageCutOff", true)->value().toDouble();
Config.writeFile();