Batteriebanner hinzugefügt
This commit is contained in:
@@ -155,18 +155,17 @@ void handleBatteryTopic(const char* topic, const char* payload) {
|
||||
}
|
||||
|
||||
// Parse payload for timestamp (optional, falls im Payload enthalten)
|
||||
uint64_t timestamp = millis();
|
||||
StaticJsonDocument<128> payloadDoc;
|
||||
if (payload && strlen(payload) > 0 && deserializeJson(payloadDoc, payload) == DeserializationError::Ok) {
|
||||
if (payloadDoc.containsKey("voltage")) {
|
||||
timestamp = payloadDoc["voltage"];
|
||||
batteryLevel = payloadDoc["voltage"];
|
||||
}
|
||||
}
|
||||
|
||||
//Berechne die Prozentzahl des Batteriestands für eine 1S LIPO batteryLevel sind Volts
|
||||
// Hier wird angenommen, dass 3.7V 100% entspricht und 3.0V 0%
|
||||
batteryLevel = batteryLevel * 1000; // Umwandlung von V in mV für genauere Berechnung
|
||||
if (batteryLevel < 3000) {
|
||||
if (batteryLevel < 3200) {
|
||||
batteryLevel = 0; // 0% bei 3.0V
|
||||
} else if (batteryLevel > 3700) {
|
||||
batteryLevel = 100; // 100% bei 3.7V
|
||||
|
||||
Reference in New Issue
Block a user