This commit is contained in:
Brendan O'Leary 2025-12-17 20:42:42 -05:00
parent abb3dc3d43
commit 71fc35845b
3 changed files with 28 additions and 25 deletions

View File

@ -69,7 +69,7 @@ void CrossPointWebServer::begin() {
} }
Serial.printf("[%lu] [WEB] [MEM] Free heap before begin: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap before begin: %d bytes\n", millis(), ESP.getFreeHeap());
Serial.printf("[%lu] [WEB] Creating web server on port %d...\n", millis(), port); Serial.printf("[%lu] [WEB] Creating web server on port %d...\n", millis(), port);
server = new WebServer(port); server = new WebServer(port);
Serial.printf("[%lu] [WEB] [MEM] Free heap after WebServer allocation: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap after WebServer allocation: %d bytes\n", millis(), ESP.getFreeHeap());
@ -111,17 +111,17 @@ void CrossPointWebServer::stop() {
} }
Serial.printf("[%lu] [WEB] [MEM] Free heap before stop: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap before stop: %d bytes\n", millis(), ESP.getFreeHeap());
server->stop(); server->stop();
Serial.printf("[%lu] [WEB] [MEM] Free heap after server->stop(): %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap after server->stop(): %d bytes\n", millis(), ESP.getFreeHeap());
delete server; delete server;
server = nullptr; server = nullptr;
running = false; running = false;
Serial.printf("[%lu] [WEB] Web server stopped\n", millis()); Serial.printf("[%lu] [WEB] Web server stopped\n", millis());
Serial.printf("[%lu] [WEB] [MEM] Free heap after delete server: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap after delete server: %d bytes\n", millis(), ESP.getFreeHeap());
// Note: Static upload variables (uploadFileName, uploadPath, uploadError) are declared // Note: Static upload variables (uploadFileName, uploadPath, uploadError) are declared
// later in the file and will be cleared when they go out of scope or on next upload // later in the file and will be cleared when they go out of scope or on next upload
Serial.printf("[%lu] [WEB] [MEM] Free heap final: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WEB] [MEM] Free heap final: %d bytes\n", millis(), ESP.getFreeHeap());
@ -452,7 +452,7 @@ void CrossPointWebServer::handleUpload() {
static unsigned long lastWriteTime = 0; static unsigned long lastWriteTime = 0;
static unsigned long uploadStartTime = 0; static unsigned long uploadStartTime = 0;
static size_t lastLoggedSize = 0; static size_t lastLoggedSize = 0;
HTTPUpload& upload = server->upload(); HTTPUpload& upload = server->upload();
if (upload.status == UPLOAD_FILE_START) { if (upload.status == UPLOAD_FILE_START) {
@ -517,22 +517,25 @@ void CrossPointWebServer::handleUpload() {
size_t written = uploadFile.write(upload.buf, upload.currentSize); size_t written = uploadFile.write(upload.buf, upload.currentSize);
unsigned long writeEndTime = millis(); unsigned long writeEndTime = millis();
unsigned long writeDuration = writeEndTime - writeStartTime; unsigned long writeDuration = writeEndTime - writeStartTime;
if (written != upload.currentSize) { if (written != upload.currentSize) {
uploadError = "Failed to write to SD card - disk may be full"; uploadError = "Failed to write to SD card - disk may be full";
uploadFile.close(); uploadFile.close();
Serial.printf("[%lu] [WEB] [UPLOAD] WRITE ERROR - expected %d, wrote %d\n", millis(), upload.currentSize, written); Serial.printf("[%lu] [WEB] [UPLOAD] WRITE ERROR - expected %d, wrote %d\n", millis(), upload.currentSize,
written);
} else { } else {
uploadSize += written; uploadSize += written;
// Log progress every 50KB or if write took >100ms // Log progress every 50KB or if write took >100ms
if (uploadSize - lastLoggedSize >= 51200 || writeDuration > 100) { if (uploadSize - lastLoggedSize >= 51200 || writeDuration > 100) {
unsigned long timeSinceStart = millis() - uploadStartTime; unsigned long timeSinceStart = millis() - uploadStartTime;
unsigned long timeSinceLastWrite = millis() - lastWriteTime; unsigned long timeSinceLastWrite = millis() - lastWriteTime;
float kbps = (uploadSize / 1024.0) / (timeSinceStart / 1000.0); float kbps = (uploadSize / 1024.0) / (timeSinceStart / 1000.0);
Serial.printf("[%lu] [WEB] [UPLOAD] Progress: %d bytes (%.1f KB), %.1f KB/s, write took %lu ms, gap since last: %lu ms\n", Serial.printf(
millis(), uploadSize, uploadSize / 1024.0, kbps, writeDuration, timeSinceLastWrite); "[%lu] [WEB] [UPLOAD] Progress: %d bytes (%.1f KB), %.1f KB/s, write took %lu ms, gap since last: %lu "
"ms\n",
millis(), uploadSize, uploadSize / 1024.0, kbps, writeDuration, timeSinceLastWrite);
lastLoggedSize = uploadSize; lastLoggedSize = uploadSize;
} }
lastWriteTime = millis(); lastWriteTime = millis();

View File

@ -49,7 +49,7 @@ void WifiScreen::onEnter() {
void WifiScreen::onExit() { void WifiScreen::onExit() {
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit start: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit start: %d bytes\n", millis(), ESP.getFreeHeap());
// Stop any ongoing WiFi scan // Stop any ongoing WiFi scan
WiFi.scanDelete(); WiFi.scanDelete();
Serial.printf("[%lu] [WIFI] [MEM] Free heap after scanDelete: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WIFI] [MEM] Free heap after scanDelete: %d bytes\n", millis(), ESP.getFreeHeap());
@ -68,16 +68,16 @@ void WifiScreen::onExit() {
vTaskDelete(displayTaskHandle); vTaskDelete(displayTaskHandle);
displayTaskHandle = nullptr; displayTaskHandle = nullptr;
} }
// Small delay to ensure task is fully deleted before cleaning up mutex // Small delay to ensure task is fully deleted before cleaning up mutex
vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
// Now safe to delete the mutex // Now safe to delete the mutex
if (renderingMutex) { if (renderingMutex) {
vSemaphoreDelete(renderingMutex); vSemaphoreDelete(renderingMutex);
renderingMutex = nullptr; renderingMutex = nullptr;
} }
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit end: %d bytes\n", millis(), ESP.getFreeHeap()); Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit end: %d bytes\n", millis(), ESP.getFreeHeap());
} }

View File

@ -205,10 +205,10 @@ void loop() {
static unsigned long lastLoopTime = 0; static unsigned long lastLoopTime = 0;
static unsigned long maxLoopDuration = 0; static unsigned long maxLoopDuration = 0;
static unsigned long lastHandleClientTime = 0; static unsigned long lastHandleClientTime = 0;
unsigned long loopStartTime = millis(); unsigned long loopStartTime = millis();
unsigned long timeSinceLastLoop = loopStartTime - lastLoopTime; unsigned long timeSinceLastLoop = loopStartTime - lastLoopTime;
// Reduce delay when webserver is running to allow faster handleClient() calls // Reduce delay when webserver is running to allow faster handleClient() calls
// This is critical for upload performance and preventing TCP timeouts // This is critical for upload performance and preventing TCP timeouts
if (crossPointWebServer.isRunning()) { if (crossPointWebServer.isRunning()) {
@ -254,25 +254,25 @@ void loop() {
// Handle web server requests if running // Handle web server requests if running
if (crossPointWebServer.isRunning()) { if (crossPointWebServer.isRunning()) {
unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime; unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
// Log if there's a significant gap between handleClient calls (>100ms) // Log if there's a significant gap between handleClient calls (>100ms)
if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) { if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) {
Serial.printf("[%lu] [LOOP] WARNING: %lu ms gap since last handleClient (activity took %lu ms)\n", Serial.printf("[%lu] [LOOP] WARNING: %lu ms gap since last handleClient (activity took %lu ms)\n", millis(),
millis(), timeSinceLastHandleClient, activityDuration); timeSinceLastHandleClient, activityDuration);
} }
crossPointWebServer.handleClient(); crossPointWebServer.handleClient();
lastHandleClientTime = millis(); lastHandleClientTime = millis();
} }
unsigned long loopDuration = millis() - loopStartTime; unsigned long loopDuration = millis() - loopStartTime;
if (loopDuration > maxLoopDuration) { if (loopDuration > maxLoopDuration) {
maxLoopDuration = loopDuration; maxLoopDuration = loopDuration;
if (maxLoopDuration > 50) { if (maxLoopDuration > 50) {
Serial.printf("[%lu] [LOOP] New max loop duration: %lu ms (activity: %lu ms)\n", Serial.printf("[%lu] [LOOP] New max loop duration: %lu ms (activity: %lu ms)\n", millis(), maxLoopDuration,
millis(), maxLoopDuration, activityDuration); activityDuration);
} }
} }
lastLoopTime = loopStartTime; lastLoopTime = loopStartTime;
} }