Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6de2e8728c | ||
|
|
60f08ea640 | ||
|
|
7fdfc79a2a | ||
|
|
894d1d25dd | ||
|
|
a3dd4b164e | ||
|
|
0f8d3d470d |
No files matched your search
+2
-2
@@ -41,11 +41,11 @@
|
|||||||
|
|
||||||
<div class="fm-card">
|
<div class="fm-card">
|
||||||
<h2>System Registration</h2>
|
<h2>System Registration</h2>
|
||||||
<p>Current Status: <strong style="color: var(--accent);">{{registered}}</strong></p>
|
<p>Current Status: <strong style="color: var(--accent);">%registered%</strong></p>
|
||||||
|
|
||||||
<div class="fm-form-group" style="margin-top: 2rem;">
|
<div class="fm-form-group" style="margin-top: 2rem;">
|
||||||
<label class="fm-label" for="filamanUrl">FilaMan API URL</label>
|
<label class="fm-label" for="filamanUrl">FilaMan API URL</label>
|
||||||
<input type="text" id="filamanUrl" class="fm-input" value="{{filamanUrl}}" placeholder="e.g. http://192.168.1.10:8000">
|
<input type="text" id="filamanUrl" class="fm-input" value="%filamanUrl%" placeholder="e.g. http://192.168.1.10:8000">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="fm-form-group">
|
<div class="fm-form-group">
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@
|
|||||||
<button id="tareBtn" class="fm-btn fm-btn-outline">Tare Scale</button>
|
<button id="tareBtn" class="fm-btn fm-btn-outline">Tare Scale</button>
|
||||||
|
|
||||||
<label class="status-pill" style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
<label class="status-pill" style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
|
||||||
<input type="checkbox" id="autoTareCheckbox" onchange="setAutoTare(this.checked);" {{autoTare}}>
|
<input type="checkbox" id="autoTareCheckbox" onchange="setAutoTare(this.checked);" %autoTare%>
|
||||||
<span>Enable Auto-TARE</span>
|
<span>Enable Auto-TARE</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+24
-6
@@ -9,8 +9,8 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
version = "3.2.7"
|
version = "3.3.0"
|
||||||
to_old_version = "3.0.9"
|
to_old_version = "3.2.0"
|
||||||
|
|
||||||
##
|
##
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
@@ -55,11 +55,29 @@ build_flags =
|
|||||||
#-DOTA_DEBUG=1
|
#-DOTA_DEBUG=1
|
||||||
-DCONFIG_OPTIMIZATION_LEVEL_DEBUG=1
|
-DCONFIG_OPTIMIZATION_LEVEL_DEBUG=1
|
||||||
-DBOOT_APP_PARTITION_OTA_0=1
|
-DBOOT_APP_PARTITION_OTA_0=1
|
||||||
-DCONFIG_LWIP_TCP_MSL=60000
|
|
||||||
-DCONFIG_LWIP_TCP_RCV_BUF_DEFAULT=4096
|
# ===== AsyncTCP Optimierungen - KRITISCH für WiFi-Stabilität =====
|
||||||
|
# Core 1 = Arduino/App Core (nicht Core 0 = WiFi/Protocol Core!)
|
||||||
|
# Schwere Callbacks auf Core 0 stören das WiFi-Radio
|
||||||
|
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1
|
||||||
|
# Längerer ACK-Timeout für instabile Verbindungen (10s statt 5s)
|
||||||
|
-DCONFIG_ASYNC_TCP_MAX_ACK_TIME=10000
|
||||||
|
# Größere Queue für mehr gleichzeitige Requests
|
||||||
|
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
|
||||||
|
# Mehr Stack für komplexere Callbacks (8KB statt 16KB default, spart RAM)
|
||||||
|
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
|
||||||
|
# Standard-Priorität beibehalten
|
||||||
|
-DCONFIG_ASYNC_TCP_PRIORITY=10
|
||||||
|
# WDT aktivieren für Crash-Recovery (war deaktiviert!)
|
||||||
|
-DCONFIG_ASYNC_TCP_USE_WDT=1
|
||||||
|
|
||||||
|
# ===== LwIP Optimierungen für OTA-Uploads (1.5-2MB) =====
|
||||||
|
# Schnellere Socket-Freigabe (30s statt 60s TIME_WAIT)
|
||||||
|
-DCONFIG_LWIP_TCP_MSL=30000
|
||||||
|
# Größerer RX-Buffer für große Uploads (8KB statt 4KB)
|
||||||
|
-DCONFIG_LWIP_TCP_RCV_BUF_DEFAULT=8192
|
||||||
|
# Max aktive TCP-Verbindungen (unverändert)
|
||||||
-DCONFIG_LWIP_MAX_ACTIVE_TCP=16
|
-DCONFIG_LWIP_MAX_ACTIVE_TCP=16
|
||||||
-DCONFIG_ASYNC_TCP_RUNNING_CORE=0
|
|
||||||
-DCONFIG_ASYNC_TCP_USE_WDT=0
|
|
||||||
|
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
scripts/extra_script.py
|
scripts/extra_script.py
|
||||||
|
|||||||
+28
-5
@@ -80,10 +80,12 @@ bool registerDevice(const String& deviceCode) {
|
|||||||
bool sendHeartbeat() {
|
bool sendHeartbeat() {
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(3000);
|
http.setTimeout(10000); // 10s statt 3s - wichtig für instabile Verbindungen
|
||||||
|
http.setReuse(true); // Keep-Alive aktivieren für bessere Performance
|
||||||
http.begin(filamanUrl + "/api/v1/devices/heartbeat");
|
http.begin(filamanUrl + "/api/v1/devices/heartbeat");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
http.addHeader("Authorization", "Device " + filamanToken);
|
http.addHeader("Authorization", "Device " + filamanToken);
|
||||||
|
http.addHeader("Connection", "keep-alive"); // Explizit Keep-Alive anfordern
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
doc["ip_address"] = WiFi.localIP().toString();
|
doc["ip_address"] = WiFi.localIP().toString();
|
||||||
String payload;
|
String payload;
|
||||||
@@ -94,6 +96,21 @@ bool sendHeartbeat() {
|
|||||||
return filamanConnected;
|
return filamanConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Heartbeat mit Retry-Logik für mehr Stabilität
|
||||||
|
bool sendHeartbeatWithRetry(int maxRetries = 2) {
|
||||||
|
for (int attempt = 0; attempt <= maxRetries; attempt++) {
|
||||||
|
if (sendHeartbeat()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (attempt < maxRetries) {
|
||||||
|
Serial.printf("Heartbeat failed, retry %d/%d...\n", attempt + 1, maxRetries);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000)); // 1s warten vor Retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("Heartbeat failed after all retries");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
||||||
Serial.printf("sendWeight: sending to API - spoolId=%d, tagUuid=%s, weight=%.1f\n", spoolId, tagUuid.c_str(), measuredWeight);
|
Serial.printf("sendWeight: sending to API - spoolId=%d, tagUuid=%s, weight=%.1f\n", spoolId, tagUuid.c_str(), measuredWeight);
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) {
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) {
|
||||||
@@ -101,10 +118,12 @@ bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(3000);
|
http.setTimeout(10000); // 10s Timeout
|
||||||
|
http.setReuse(true);
|
||||||
http.begin(filamanUrl + "/api/v1/devices/scale/weight");
|
http.begin(filamanUrl + "/api/v1/devices/scale/weight");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
http.addHeader("Authorization", "Device " + filamanToken);
|
http.addHeader("Authorization", "Device " + filamanToken);
|
||||||
|
http.addHeader("Connection", "keep-alive");
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
// Only add spool_id if it's > 0 (for NTAG tags with spool ID)
|
// Only add spool_id if it's > 0 (for NTAG tags with spool ID)
|
||||||
// For Bambu tags (spoolId == 0), only send tag_uuid
|
// For Bambu tags (spoolId == 0), only send tag_uuid
|
||||||
@@ -146,10 +165,12 @@ bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
|
|||||||
bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid) {
|
bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locationTagUuid) {
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(3000);
|
http.setTimeout(10000); // 10s Timeout
|
||||||
|
http.setReuse(true);
|
||||||
http.begin(filamanUrl + "/api/v1/devices/scale/locate");
|
http.begin(filamanUrl + "/api/v1/devices/scale/locate");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
http.addHeader("Authorization", "Device " + filamanToken);
|
http.addHeader("Authorization", "Device " + filamanToken);
|
||||||
|
http.addHeader("Connection", "keep-alive");
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
if (spoolId > 0) doc["spool_id"] = spoolId;
|
if (spoolId > 0) doc["spool_id"] = spoolId;
|
||||||
if (spoolTagUuid.length() > 0) doc["spool_tag_uuid"] = spoolTagUuid;
|
if (spoolTagUuid.length() > 0) doc["spool_tag_uuid"] = spoolTagUuid;
|
||||||
@@ -165,10 +186,12 @@ bool sendLocation(int spoolId, String spoolTagUuid, int locationId, String locat
|
|||||||
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight) {
|
bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, String errorMessage, float remainingWeight) {
|
||||||
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
if (!checkFilamanRegistration() || WiFi.status() != WL_CONNECTED) return false;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setTimeout(5000);
|
http.setTimeout(10000); // 10s Timeout
|
||||||
|
http.setReuse(true);
|
||||||
http.begin(filamanUrl + "/api/v1/devices/rfid-result");
|
http.begin(filamanUrl + "/api/v1/devices/rfid-result");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
http.addHeader("Authorization", "Device " + filamanToken);
|
http.addHeader("Authorization", "Device " + filamanToken);
|
||||||
|
http.addHeader("Connection", "keep-alive");
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
doc["success"] = success;
|
doc["success"] = success;
|
||||||
@@ -205,7 +228,7 @@ void filamanApiTask(void* pvParameters) {
|
|||||||
if (hasReq) {
|
if (hasReq) {
|
||||||
filamanApiState = API_TRANSMITTING;
|
filamanApiState = API_TRANSMITTING;
|
||||||
switch (req.type) {
|
switch (req.type) {
|
||||||
case API_REQUEST_HEARTBEAT: sendHeartbeat(); break;
|
case API_REQUEST_HEARTBEAT: sendHeartbeatWithRetry(2); break; // Mit Retry-Logik
|
||||||
case API_REQUEST_WEIGHT: sendWeight(req.id1, req.str1, req.val); break;
|
case API_REQUEST_WEIGHT: sendWeight(req.id1, req.str1, req.val); break;
|
||||||
case API_REQUEST_LOCATE: sendLocation(req.id1, req.str1, req.id2, req.str2); break;
|
case API_REQUEST_LOCATE: sendLocation(req.id1, req.str1, req.id2, req.str2); break;
|
||||||
case API_REQUEST_RFID_RESULT: sendRfidResult(req.str1, req.id1, req.id2, req.bool1, req.str3, req.remainingWeight); break;
|
case API_REQUEST_RFID_RESULT: sendRfidResult(req.str1, req.id1, req.id2, req.bool1, req.str3, req.remainingWeight); break;
|
||||||
|
|||||||
+12
-2
@@ -57,10 +57,20 @@ String readFile(const char* filename) {
|
|||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String content = "";
|
|
||||||
|
// Effizient: Speicher vorab allokieren und in Blöcken lesen
|
||||||
|
// Alte Implementierung war O(n²) wegen Byte-für-Byte String-Konkatenation
|
||||||
|
size_t fileSize = file.size();
|
||||||
|
String content;
|
||||||
|
content.reserve(fileSize + 1); // Speicher vorab allokieren
|
||||||
|
|
||||||
|
// Lese in 512-Byte Blöcken statt Byte für Byte
|
||||||
|
char buffer[512];
|
||||||
while (file.available()) {
|
while (file.available()) {
|
||||||
content += (char)file.read();
|
size_t bytesRead = file.readBytes(buffer, sizeof(buffer));
|
||||||
|
content.concat(buffer, bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -141,8 +141,14 @@ void loop() {
|
|||||||
{
|
{
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
oledCheckSleep(); // Put display to sleep if timeout elapsed
|
oledCheckSleep(); // Put display to sleep if timeout elapsed
|
||||||
// Clean up dead websocket clients periodically instead of on connect
|
}
|
||||||
if(currentMillis % 10000 < 50) ws.cleanupClients();
|
|
||||||
|
// WebSocket Cleanup alle 5 Sekunden (häufiger als vorher)
|
||||||
|
// Tote Clients können WiFi-Ressourcen blockieren
|
||||||
|
static unsigned long lastWsCleanup = 0;
|
||||||
|
if (currentMillis - lastWsCleanup >= 5000) {
|
||||||
|
ws.cleanupClients();
|
||||||
|
lastWsCleanup = currentMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Periodic FilaMan heartbeat
|
// Periodic FilaMan heartbeat
|
||||||
|
|||||||
+31
-24
@@ -16,6 +16,7 @@ static int currentUpdateCommand = 0;
|
|||||||
static size_t updateTotalSize = 0;
|
static size_t updateTotalSize = 0;
|
||||||
static size_t updateWritten = 0;
|
static size_t updateWritten = 0;
|
||||||
static bool isSpiffsUpdate = false;
|
static bool isSpiffsUpdate = false;
|
||||||
|
static size_t lastYieldAt = 0; // Für WiFi-Yield während großer Uploads
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two version strings and determines if version1 is less than version2
|
* Compares two version strings and determines if version1 is less than version2
|
||||||
@@ -64,11 +65,18 @@ void espRestart() {
|
|||||||
|
|
||||||
void sendUpdateProgress(int progress, const char* status = nullptr, const char* message = nullptr) {
|
void sendUpdateProgress(int progress, const char* status = nullptr, const char* message = nullptr) {
|
||||||
static int lastSentProgress = -1;
|
static int lastSentProgress = -1;
|
||||||
|
static unsigned long lastSendTime = 0;
|
||||||
|
|
||||||
// Verhindere zu häufige Updates
|
unsigned long now = millis();
|
||||||
|
|
||||||
|
// Verhindere zu häufige Updates - mindestens 500ms zwischen Progress-Updates
|
||||||
|
// Dies reduziert WebSocket-Traffic während des Uploads erheblich
|
||||||
if (progress == lastSentProgress && !status && !message) {
|
if (progress == lastSentProgress && !status && !message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (now - lastSendTime < 500 && progress < 100 && !status) {
|
||||||
|
return; // Throttle normale Progress-Updates
|
||||||
|
}
|
||||||
|
|
||||||
String progressMsg = "{\"type\":\"updateProgress\",\"progress\":" + String(progress);
|
String progressMsg = "{\"type\":\"updateProgress\",\"progress\":" + String(progress);
|
||||||
if (status) {
|
if (status) {
|
||||||
@@ -79,23 +87,13 @@ void sendUpdateProgress(int progress, const char* status = nullptr, const char*
|
|||||||
}
|
}
|
||||||
progressMsg += "}";
|
progressMsg += "}";
|
||||||
|
|
||||||
if (progress >= 100) {
|
// Sende Progress-Update (nur einmal, nicht mehrfach)
|
||||||
// Sende die Nachricht nur einmal für den Abschluss
|
ws.textAll(progressMsg);
|
||||||
ws.textAll("{\"type\":\"updateProgress\",\"progress\":100,\"status\":\"success\",\"message\":\"Update successful! Restarting device...\"}");
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sende die Nachricht mehrmals mit Verzögerung für wichtige Updates
|
|
||||||
if (status || abs(progress - lastSentProgress) >= 10 || progress == 100) {
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
ws.textAll(progressMsg);
|
|
||||||
delay(100); // Längerer Delay zwischen Nachrichten
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ws.textAll(progressMsg);
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Yield für WiFi-Stack nach jedem WebSocket-Send
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
|
||||||
|
lastSendTime = now;
|
||||||
lastSentProgress = progress;
|
lastSentProgress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +130,7 @@ void handleUpdate(AsyncWebServer &server) {
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
updateTotalSize = request->contentLength();
|
updateTotalSize = request->contentLength();
|
||||||
updateWritten = 0;
|
updateWritten = 0;
|
||||||
|
lastYieldAt = 0; // Reset yield counter
|
||||||
isSpiffsUpdate = (filename.indexOf("website") > -1);
|
isSpiffsUpdate = (filename.indexOf("website") > -1);
|
||||||
|
|
||||||
if (isSpiffsUpdate) {
|
if (isSpiffsUpdate) {
|
||||||
@@ -147,14 +146,14 @@ void handleUpdate(AsyncWebServer &server) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendUpdateProgress(5, "starting", "Starting SPIFFS update...");
|
sendUpdateProgress(5, "starting", "Starting SPIFFS update...");
|
||||||
vTaskDelay(pdMS_TO_TICKS(200));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
} else {
|
} else {
|
||||||
if (!Update.begin(updateTotalSize)) {
|
if (!Update.begin(updateTotalSize)) {
|
||||||
request->send(400, "application/json", "{\"success\":false,\"message\":\"Update initialization failed\"}");
|
request->send(400, "application/json", "{\"success\":false,\"message\":\"Update initialization failed\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendUpdateProgress(0, "starting", "Starting firmware update...");
|
sendUpdateProgress(0, "starting", "Starting firmware update...");
|
||||||
vTaskDelay(pdMS_TO_TICKS(200));
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,22 +164,30 @@ void handleUpdate(AsyncWebServer &server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateWritten += len;
|
updateWritten += len;
|
||||||
|
|
||||||
|
// KRITISCH: Yield alle 32KB für WiFi-Stack bei großen Uploads (1.5-2MB)
|
||||||
|
// Ohne dies kann der WiFi-Stack blockieren und der Upload hängen bleiben
|
||||||
|
if (updateWritten - lastYieldAt >= 32768) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(5)); // Kurze Pause für WiFi-Stack
|
||||||
|
lastYieldAt = updateWritten;
|
||||||
|
}
|
||||||
|
|
||||||
int currentProgress;
|
int currentProgress;
|
||||||
|
|
||||||
// Berechne den Fortschritt basierend auf dem Update-Typ
|
// Berechne den Fortschritt basierend auf dem Update-Typ
|
||||||
if (isSpiffsUpdate) {
|
if (isSpiffsUpdate) {
|
||||||
// SPIFFS: 5-75% für Upload
|
// SPIFFS: 5-100% für Upload
|
||||||
currentProgress = 6 + (updateWritten * 100) / updateTotalSize;
|
currentProgress = 5 + (updateWritten * 95) / updateTotalSize;
|
||||||
} else {
|
} else {
|
||||||
// Firmware: 0-100% für Upload
|
// Firmware: 0-100% für Upload
|
||||||
currentProgress = 1 + (updateWritten * 100) / updateTotalSize;
|
currentProgress = (updateWritten * 100) / updateTotalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lastProgress = -1;
|
static int lastProgress = -1;
|
||||||
if (currentProgress != lastProgress && (currentProgress % 10 == 0 || final)) {
|
// Nur alle 5% Progress-Updates senden (reduziert WebSocket-Traffic)
|
||||||
|
if (currentProgress != lastProgress && (currentProgress % 5 == 0 || final)) {
|
||||||
sendUpdateProgress(currentProgress, "uploading");
|
sendUpdateProgress(currentProgress, "uploading");
|
||||||
oledShowProgressBar(currentProgress, 100, tr(STR_UPDATE), tr(STR_DOWNLOAD));
|
oledShowProgressBar(currentProgress, 100, tr(STR_UPDATE), tr(STR_DOWNLOAD));
|
||||||
vTaskDelay(pdMS_TO_TICKS(50));
|
|
||||||
lastProgress = currentProgress;
|
lastProgress = currentProgress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-46
@@ -18,6 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NO_CACHE "no-cache, no-store, must-revalidate"
|
#define NO_CACHE "no-cache, no-store, must-revalidate"
|
||||||
|
#define CACHE_ASSETS "max-age=86400" // 24h Cache für statische Assets
|
||||||
|
|
||||||
AsyncWebServer server(webserverPort);
|
AsyncWebServer server(webserverPort);
|
||||||
AsyncWebSocket ws("/ws");
|
AsyncWebSocket ws("/ws");
|
||||||
@@ -25,6 +26,15 @@ AsyncWebSocket ws("/ws");
|
|||||||
uint8_t lastSuccess = 0;
|
uint8_t lastSuccess = 0;
|
||||||
nfcReaderStateType lastnfcReaderState = NFC_IDLE;
|
nfcReaderStateType lastnfcReaderState = NFC_IDLE;
|
||||||
|
|
||||||
|
// Template-Processor für dynamische Seiten (ESPAsyncWebServer built-in)
|
||||||
|
// Ersetzt %variable% Platzhalter in HTML-Dateien
|
||||||
|
String templateProcessor(const String& var) {
|
||||||
|
if (var == "registered") return filamanRegistered ? "Registered" : "Not Registered";
|
||||||
|
if (var == "filamanUrl") return filamanUrl;
|
||||||
|
if (var == "autoTare") return autoTare ? "checked" : "";
|
||||||
|
return String(); // Unbekannte Variable - leer zurückgeben
|
||||||
|
}
|
||||||
|
|
||||||
void sendNfcDataToClient(AsyncWebSocketClient *client) {
|
void sendNfcDataToClient(AsyncWebSocketClient *client) {
|
||||||
if(!client) return;
|
if(!client) return;
|
||||||
switch(nfcReaderState){
|
switch(nfcReaderState){
|
||||||
@@ -119,69 +129,47 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
ws.onEvent(onWsEvent);
|
ws.onEvent(onWsEvent);
|
||||||
server.addHandler(&ws);
|
server.addHandler(&ws);
|
||||||
|
|
||||||
// Static Routes
|
// ===== STATISCHE ASSETS mit serveStatic() =====
|
||||||
|
// Optimiert für concurrent Requests, mit 24h Browser-Cache
|
||||||
|
// serveStatic() ist nicht-blockierend und handhabt parallele Requests besser
|
||||||
|
server.serveStatic("/style.css", LittleFS, "/style.css")
|
||||||
|
.setCacheControl(CACHE_ASSETS);
|
||||||
|
server.serveStatic("/logo.png", LittleFS, "/logo.png")
|
||||||
|
.setCacheControl(CACHE_ASSETS);
|
||||||
|
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico")
|
||||||
|
.setCacheControl(CACHE_ASSETS);
|
||||||
|
|
||||||
|
// ===== STATISCHE HTML-SEITEN (ohne Template-Ersetzung) =====
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("Web: Request /");
|
Serial.println("Web: Request /");
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/index.html", "text/html");
|
request->send(LittleFS, "/index.html", "text/html");
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("/waage", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
Serial.println("Web: Request /waage");
|
|
||||||
String html = readFile("/waage.html");
|
|
||||||
html.replace("{{autoTare}}", autoTare ? "checked" : "");
|
|
||||||
auto response = request->beginResponse(200, "text/html", html);
|
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("/setup", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
Serial.println("Web: Request /setup");
|
|
||||||
String html = readFile("/setup.html");
|
|
||||||
html.replace("{{registered}}", filamanRegistered ? "Registered" : "Not Registered");
|
|
||||||
html.replace("{{filamanUrl}}", filamanUrl);
|
|
||||||
auto response = request->beginResponse(200, "text/html", html);
|
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/wifi", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/wifi", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("Web: Request /wifi");
|
Serial.println("Web: Request /wifi");
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/wifi.html", "text/html");
|
request->send(LittleFS, "/wifi.html", "text/html");
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
Serial.println("Web: Request /upgrade");
|
Serial.println("Web: Request /upgrade");
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/upgrade.html", "text/html");
|
request->send(LittleFS, "/upgrade.html", "text/html");
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/version.txt", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/version.txt", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/version.txt", "text/plain");
|
request->send(LittleFS, "/version.txt", "text/plain");
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request){
|
// ===== DYNAMISCHE HTML-SEITEN (mit Template-Processor) =====
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/style.css", "text/css");
|
// Nutzt den eingebauten Template-Processor für %variable% Ersetzung
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
// Nicht-blockierend: Datei wird gestreamt und Variablen on-the-fly ersetzt
|
||||||
request->send(response);
|
server.on("/waage", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
Serial.println("Web: Request /waage");
|
||||||
|
request->send(LittleFS, "/waage.html", "text/html", false, templateProcessor);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/logo.png", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/setup", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/logo.png", "image/png");
|
Serial.println("Web: Request /setup");
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
request->send(LittleFS, "/setup.html", "text/html", false, templateProcessor);
|
||||||
request->send(response);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/favicon.ico", "image/x-icon");
|
|
||||||
response->addHeader("Cache-Control", NO_CACHE);
|
|
||||||
request->send(response);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
|
|||||||
+14
-8
@@ -17,15 +17,15 @@ void wifiSettings() {
|
|||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.setHostname("FilaMan");
|
WiFi.setHostname("FilaMan");
|
||||||
|
|
||||||
// Wir lassen das Power Management (Sleep) auf dem ESP-Standard.
|
// KRITISCH: Power-Save deaktivieren für stabilen Webserver-Betrieb
|
||||||
// Ein erzwungenes Ausschalten führt zu RF-Abstürzen bei vielen asynchronen HTTP-Requests.
|
// Ohne dies geht WiFi in Modem-Sleep und verpasst Requests/Responses
|
||||||
|
// Dies ist die Hauptursache für Verbindungsabbrüche bei regelmäßigen API-Calls
|
||||||
|
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||||
|
|
||||||
// Angemessene Sendeleistung (reduziert Hitzeprobleme)
|
// Angemessene Sendeleistung (reduziert Hitzeprobleme)
|
||||||
WiFi.setTxPower(WIFI_POWER_17dBm); // Set stable transmit power (default is 19.5 which gets hot)
|
WiFi.setTxPower(WIFI_POWER_17dBm);
|
||||||
|
|
||||||
// Wir überlassen die Protokoll-Aushandlung (b/g/n) dem Treiber. Harte Vorgaben crashen unter Last.
|
|
||||||
|
|
||||||
// Aktiviere WiFi-Roaming für bessere Stabilität
|
// Aktiviere WiFi-Roaming für bessere Stabilität bei schwachem Signal
|
||||||
esp_wifi_set_rssi_threshold(-80);
|
esp_wifi_set_rssi_threshold(-80);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +76,13 @@ void checkWiFiConnection() {
|
|||||||
if (WiFi.status() != WL_CONNECTED)
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
{
|
{
|
||||||
if (wifiOn) {
|
if (wifiOn) {
|
||||||
Serial.println("WiFi connection lost. LwIP is auto-reconnecting...");
|
Serial.println("WiFi connection lost. Attempting active reconnect...");
|
||||||
wifiOn = false;
|
wifiOn = false;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
oledDisplayText(tr(STR_WIFI_RECONNECTING));
|
oledDisplayText(tr(STR_WIFI_RECONNECTING));
|
||||||
|
|
||||||
|
// Aktiver Reconnect-Versuch statt nur auf LwIP auto-reconnect zu warten
|
||||||
|
WiFi.reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
wifiErrorCounter++;
|
wifiErrorCounter++;
|
||||||
@@ -95,10 +98,13 @@ void checkWiFiConnection() {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!wifiOn) {
|
if (!wifiOn) {
|
||||||
Serial.println("WiFi reconnected.");
|
Serial.println("WiFi reconnected successfully.");
|
||||||
wifiErrorCounter = 0;
|
wifiErrorCounter = 0;
|
||||||
wifiOn = true;
|
wifiOn = true;
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
|
|
||||||
|
// Power-Save erneut deaktivieren nach Reconnect (wird manchmal zurückgesetzt)
|
||||||
|
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||||
} else {
|
} else {
|
||||||
// Reset error counter if we are connected (just to be safe)
|
// Reset error counter if we are connected (just to be safe)
|
||||||
wifiErrorCounter = 0;
|
wifiErrorCounter = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user