rewrite for ElegantOTA, implement battery for master

This commit is contained in:
2025-07-25 18:30:02 +02:00
parent 70fd2b362c
commit d82d82cd20
6 changed files with 76 additions and 15 deletions

View File

@@ -171,7 +171,19 @@
name="password" name="password"
placeholder="WLAN-Passwort eingeben" placeholder="WLAN-Passwort eingeben"
/> />
<div class="section">
<div
id="systemInfo"
style="
background: white;
padding: 20px;
border-radius: 10px;
font-family: monospace;
font-size: 14px;
"
>
<div>STA IP-Adresse: <span id="STAipAddress">Laden...</span></div> <div>STA IP-Adresse: <span id="STAipAddress">Laden...</span></div>
</div>
</div> </div>
<div class="button-group"> <div class="button-group">
<button type="submit" id="wifiSubmitBtn" class="btn btn-primary"> <button type="submit" id="wifiSubmitBtn" class="btn btn-primary">

View File

@@ -27,11 +27,11 @@ board_build.psram = disabled
lib_deps = lib_deps =
bblanchon/ArduinoJson@^7.4.1 bblanchon/ArduinoJson@^7.4.1
esp32async/ESPAsyncWebServer@^3.7.7 esp32async/ESPAsyncWebServer@^3.7.7
lostincompilation/PrettyOTA@^1.1.3
esp32async/AsyncTCP@^3.4.2 esp32async/AsyncTCP@^3.4.2
mlesniew/PicoMQTT@^1.3.0 mlesniew/PicoMQTT@^1.3.0
miguelbalboa/MFRC522@^1.4.12 miguelbalboa/MFRC522@^1.4.12
adafruit/RTClib@^2.1.4 adafruit/RTClib@^2.1.4
ayushsharma82/ElegantOTA@^3.1.7
[env:wemos_d1_mini32_OTA] [env:wemos_d1_mini32_OTA]
board = wemos_d1_mini32 board = wemos_d1_mini32
@@ -39,11 +39,11 @@ monitor_speed = 115200
lib_deps = lib_deps =
bblanchon/ArduinoJson@^7.4.1 bblanchon/ArduinoJson@^7.4.1
esp32async/ESPAsyncWebServer@^3.7.7 esp32async/ESPAsyncWebServer@^3.7.7
lostincompilation/PrettyOTA@^1.1.3
esp32async/AsyncTCP@^3.4.2 esp32async/AsyncTCP@^3.4.2
mlesniew/PicoMQTT@^1.3.0 mlesniew/PicoMQTT@^1.3.0
miguelbalboa/MFRC522@^1.4.12 miguelbalboa/MFRC522@^1.4.12
adafruit/RTClib@^2.1.4 adafruit/RTClib@^2.1.4
ayushsharma82/ElegantOTA@^3.1.7
upload_protocol = espota upload_protocol = espota
upload_port = 192.168.1.94 upload_port = 192.168.1.94
@@ -58,11 +58,11 @@ board_build.psram = disabled
lib_deps = lib_deps =
bblanchon/ArduinoJson@^7.4.1 bblanchon/ArduinoJson@^7.4.1
esp32async/ESPAsyncWebServer@^3.7.7 esp32async/ESPAsyncWebServer@^3.7.7
lostincompilation/PrettyOTA@^1.1.3
esp32async/AsyncTCP@^3.4.2 esp32async/AsyncTCP@^3.4.2
mlesniew/PicoMQTT@^1.3.0 mlesniew/PicoMQTT@^1.3.0
miguelbalboa/MFRC522@^1.4.12 miguelbalboa/MFRC522@^1.4.12
adafruit/RTClib@^2.1.4 adafruit/RTClib@^2.1.4
ayushsharma82/ElegantOTA@^3.1.7
[env:esp32thing] [env:esp32thing]
board = esp32thing board = esp32thing
@@ -70,6 +70,7 @@ monitor_speed = 115200
build_flags = build_flags =
-DBOARD_HAS_PSRAM -DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-issue
-DBATTERY_PIN=36
board_upload.flash_size = 16MB board_upload.flash_size = 16MB
board_build.partitions = default_16MB.csv board_build.partitions = default_16MB.csv
targets = uploadfs targets = uploadfs
@@ -77,8 +78,8 @@ board_build.psram = disabled
lib_deps = lib_deps =
bblanchon/ArduinoJson@^7.4.1 bblanchon/ArduinoJson@^7.4.1
esp32async/ESPAsyncWebServer@^3.7.7 esp32async/ESPAsyncWebServer@^3.7.7
lostincompilation/PrettyOTA@^1.1.3
esp32async/AsyncTCP@^3.4.2 esp32async/AsyncTCP@^3.4.2
mlesniew/PicoMQTT@^1.3.0 mlesniew/PicoMQTT@^1.3.0
miguelbalboa/MFRC522@^1.4.12 miguelbalboa/MFRC522@^1.4.12
adafruit/RTClib@^2.1.4 adafruit/RTClib@^2.1.4
ayushsharma82/ElegantOTA@^3.1.7

35
src/battery.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include <Arduino.h>
unsigned long lastBatteryRead = 0;
void setupBattery() {
// GPIO Setup
pinMode(BATTERY_PIN, INPUT);
}
float readBatteryVoltage() {
uint32_t Vbatt = 0;
for (int i = 0; i < 16; i++) {
Vbatt += analogReadMilliVolts(BATTERY_PIN);
}
float avg = Vbatt / 16.0;
Serial.print("ADC raw (mV): ");
Serial.println(avg);
float Vbattf = avg * 2 / 1000.0;
lastBatteryRead = millis(); // Update last read time
return Vbattf;
}
void loopBattery() {
if (millis() - lastBatteryRead > 10000) { // Read every 10 seconds
float voltage = readBatteryVoltage();
Serial.print("Battery Voltage: ");
Serial.println(voltage);
// Here you can add code to send the voltage to a server or display it
// For example, you could publish it to MQTT or update a web interface
}
}

View File

@@ -213,8 +213,7 @@ void handleBatteryTopic(const char *topic, const char *payload) {
pushUpdateToFrontend( pushUpdateToFrontend(
json); // Diese Funktion schickt das JSON an alle WebSocket-Clients json); // Diese Funktion schickt das JSON an alle WebSocket-Clients
// Serial.printf("Battery level for %s (%s): %d%%\n", buttonType.c_str(), // Serial.printf("Battery level for %s (%s): %d%%\n", buttonType.c_str(),macStr.c_str(), batteryLevelP);
macStr.c_str(), batteryLevelP);
} }
/** /**

View File

@@ -8,12 +8,12 @@
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include <Preferences.h> #include <Preferences.h>
#include <PrettyOTA.h>
#include <SPIFFS.h> #include <SPIFFS.h>
#include <esp_now.h> #include <esp_now.h>
#include <esp_wifi.h> #include <esp_wifi.h>
#include <communication.h> #include <communication.h>
#include <databasebackend.h> #include <databasebackend.h>
#include <debug.h> #include <debug.h>
@@ -22,6 +22,7 @@
#include <timesync.h> #include <timesync.h>
#include <webserverrouter.h> #include <webserverrouter.h>
#include <wificlass.h> #include <wificlass.h>
#include <battery.h>
const char *firmwareversion = "1.0.0"; // Version der Firmware const char *firmwareversion = "1.0.0"; // Version der Firmware
@@ -299,12 +300,15 @@ void setup() {
setupWebSocket(); setupWebSocket();
setupLED(); setupLED();
setupMqttServer(); // MQTT Server initialisieren setupMqttServer(); // MQTT Server initialisieren
setupRFID(); //setupBattery();
//setupRFID();
} }
void loop() { void loop() {
loopOTA(); // OTA Loop aufrufen
checkAutoReset(); checkAutoReset();
loopMqttServer(); // MQTT Server in der Loop aufrufen loopMqttServer(); // MQTT Server in der Loop aufrufen
loopWebSocket(); loopWebSocket();
loopRFID(); // RFID Loop aufrufen //loopBattery(); // Batterie-Loop aufrufen
//loopRFID(); // RFID Loop aufrufen
} }

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include <ESPmDNS.h> // <-- mDNS hinzufügen #include <ESPmDNS.h> // <-- mDNS hinzufügen
#include <PrettyOTA.h>
#include <WiFi.h> #include <WiFi.h>
#include <esp_now.h> #include <esp_now.h>
#include <esp_wifi.h> #include <esp_wifi.h>
#include <ElegantOTA.h> // OTA Updates
#include "licenceing.h" #include "licenceing.h"
#include "master.h" #include "master.h"
@@ -12,10 +12,11 @@
String uniqueSSID; String uniqueSSID;
PrettyOTA OTAUpdates;
String getUniqueSSID(); String getUniqueSSID();
bool isInternetAvailable(); bool isInternetAvailable();
void loopOTA();
void setupOTA();
// Initialisiert das WLAN als Access Point oder Station und startet mDNS/OTA. // Initialisiert das WLAN als Access Point oder Station und startet mDNS/OTA.
void setupWifi() { void setupWifi() {
@@ -76,16 +77,25 @@ void setupWifi() {
// Initialisiert das OTA-Update-System (PrettyOTA) für Firmware-Updates. // Initialisiert das OTA-Update-System (PrettyOTA) für Firmware-Updates.
void setupOTA(AsyncWebServer *server) { void setupOTA(AsyncWebServer *server) {
// Initialize PrettyOTA // Initialize PrettyOTA
OTAUpdates.Begin(server);
ElegantOTA.begin(server);
//OTAUpdates.Begin(server);
// Set unique Hardware-ID for your hardware/board // Set unique Hardware-ID for your hardware/board
OTAUpdates.SetHardwareID("AquaCross-Master"); //OTAUpdates.SetHardwareID("AquaCross-Master");
// Set firmware version to 1.0.0 // Set firmware version to 1.0.0
OTAUpdates.SetAppVersion(firmwareversion); //OTAUpdates.SetAppVersion(firmwareversion);
// Set current build time and date // Set current build time and date
PRETTY_OTA_SET_CURRENT_BUILD_TIME_AND_DATE(); //PRETTY_OTA_SET_CURRENT_BUILD_TIME_AND_DATE();
}
void loopOTA(){
ElegantOTA.loop();
} }
// Generiert eine eindeutige SSID auf Basis der MAC-Adresse. // Generiert eine eindeutige SSID auf Basis der MAC-Adresse.