rewrite for ElegantOTA, implement battery for master
This commit is contained in:
@@ -171,7 +171,19 @@
|
||||
name="password"
|
||||
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>
|
||||
</div>
|
||||
<div class="button-group">
|
||||
<button type="submit" id="wifiSubmitBtn" class="btn btn-primary">
|
||||
|
||||
@@ -27,11 +27,11 @@ board_build.psram = disabled
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.4.1
|
||||
esp32async/ESPAsyncWebServer@^3.7.7
|
||||
lostincompilation/PrettyOTA@^1.1.3
|
||||
esp32async/AsyncTCP@^3.4.2
|
||||
mlesniew/PicoMQTT@^1.3.0
|
||||
miguelbalboa/MFRC522@^1.4.12
|
||||
adafruit/RTClib@^2.1.4
|
||||
ayushsharma82/ElegantOTA@^3.1.7
|
||||
|
||||
[env:wemos_d1_mini32_OTA]
|
||||
board = wemos_d1_mini32
|
||||
@@ -39,11 +39,11 @@ monitor_speed = 115200
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.4.1
|
||||
esp32async/ESPAsyncWebServer@^3.7.7
|
||||
lostincompilation/PrettyOTA@^1.1.3
|
||||
esp32async/AsyncTCP@^3.4.2
|
||||
mlesniew/PicoMQTT@^1.3.0
|
||||
miguelbalboa/MFRC522@^1.4.12
|
||||
adafruit/RTClib@^2.1.4
|
||||
ayushsharma82/ElegantOTA@^3.1.7
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.1.94
|
||||
|
||||
@@ -58,11 +58,11 @@ board_build.psram = disabled
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.4.1
|
||||
esp32async/ESPAsyncWebServer@^3.7.7
|
||||
lostincompilation/PrettyOTA@^1.1.3
|
||||
esp32async/AsyncTCP@^3.4.2
|
||||
mlesniew/PicoMQTT@^1.3.0
|
||||
miguelbalboa/MFRC522@^1.4.12
|
||||
adafruit/RTClib@^2.1.4
|
||||
ayushsharma82/ElegantOTA@^3.1.7
|
||||
|
||||
[env:esp32thing]
|
||||
board = esp32thing
|
||||
@@ -70,6 +70,7 @@ monitor_speed = 115200
|
||||
build_flags =
|
||||
-DBOARD_HAS_PSRAM
|
||||
-mfix-esp32-psram-cache-issue
|
||||
-DBATTERY_PIN=36
|
||||
board_upload.flash_size = 16MB
|
||||
board_build.partitions = default_16MB.csv
|
||||
targets = uploadfs
|
||||
@@ -77,8 +78,8 @@ board_build.psram = disabled
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^7.4.1
|
||||
esp32async/ESPAsyncWebServer@^3.7.7
|
||||
lostincompilation/PrettyOTA@^1.1.3
|
||||
esp32async/AsyncTCP@^3.4.2
|
||||
mlesniew/PicoMQTT@^1.3.0
|
||||
miguelbalboa/MFRC522@^1.4.12
|
||||
adafruit/RTClib@^2.1.4
|
||||
ayushsharma82/ElegantOTA@^3.1.7
|
||||
|
||||
35
src/battery.h
Normal file
35
src/battery.h
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -213,8 +213,7 @@ void handleBatteryTopic(const char *topic, const char *payload) {
|
||||
pushUpdateToFrontend(
|
||||
json); // Diese Funktion schickt das JSON an alle WebSocket-Clients
|
||||
|
||||
// Serial.printf("Battery level for %s (%s): %d%%\n", buttonType.c_str(),
|
||||
macStr.c_str(), batteryLevelP);
|
||||
// Serial.printf("Battery level for %s (%s): %d%%\n", buttonType.c_str(),macStr.c_str(), batteryLevelP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Preferences.h>
|
||||
#include <PrettyOTA.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <esp_now.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
|
||||
|
||||
#include <communication.h>
|
||||
#include <databasebackend.h>
|
||||
#include <debug.h>
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <timesync.h>
|
||||
#include <webserverrouter.h>
|
||||
#include <wificlass.h>
|
||||
#include <battery.h>
|
||||
|
||||
|
||||
const char *firmwareversion = "1.0.0"; // Version der Firmware
|
||||
@@ -299,12 +300,15 @@ void setup() {
|
||||
setupWebSocket();
|
||||
setupLED();
|
||||
setupMqttServer(); // MQTT Server initialisieren
|
||||
setupRFID();
|
||||
//setupBattery();
|
||||
//setupRFID();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
loopOTA(); // OTA Loop aufrufen
|
||||
checkAutoReset();
|
||||
loopMqttServer(); // MQTT Server in der Loop aufrufen
|
||||
loopWebSocket();
|
||||
loopRFID(); // RFID Loop aufrufen
|
||||
//loopBattery(); // Batterie-Loop aufrufen
|
||||
//loopRFID(); // RFID Loop aufrufen
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ESPmDNS.h> // <-- mDNS hinzufügen
|
||||
#include <PrettyOTA.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_now.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <ElegantOTA.h> // OTA Updates
|
||||
|
||||
#include "licenceing.h"
|
||||
#include "master.h"
|
||||
@@ -12,10 +12,11 @@
|
||||
|
||||
String uniqueSSID;
|
||||
|
||||
PrettyOTA OTAUpdates;
|
||||
|
||||
String getUniqueSSID();
|
||||
bool isInternetAvailable();
|
||||
void loopOTA();
|
||||
void setupOTA();
|
||||
|
||||
// Initialisiert das WLAN als Access Point oder Station und startet mDNS/OTA.
|
||||
void setupWifi() {
|
||||
@@ -76,16 +77,25 @@ void setupWifi() {
|
||||
// Initialisiert das OTA-Update-System (PrettyOTA) für Firmware-Updates.
|
||||
void setupOTA(AsyncWebServer *server) {
|
||||
// Initialize PrettyOTA
|
||||
OTAUpdates.Begin(server);
|
||||
|
||||
ElegantOTA.begin(server);
|
||||
|
||||
//OTAUpdates.Begin(server);
|
||||
|
||||
// Set unique Hardware-ID for your hardware/board
|
||||
OTAUpdates.SetHardwareID("AquaCross-Master");
|
||||
//OTAUpdates.SetHardwareID("AquaCross-Master");
|
||||
|
||||
// Set firmware version to 1.0.0
|
||||
OTAUpdates.SetAppVersion(firmwareversion);
|
||||
//OTAUpdates.SetAppVersion(firmwareversion);
|
||||
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user