From 74026a3ce0cb2f3d0c2d890714cb60cf10c10e38 Mon Sep 17 00:00:00 2001 From: Victus Date: Sun, 10 May 2026 23:02:00 +0200 Subject: [PATCH] Dodano szczegolowe logi do debugowania crashy w Measure, UploadManager i APIClient --- src/APIClient.cpp | 4 ++++ src/UploadManager.cpp | 7 +++++++ src/main.cpp | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/APIClient.cpp b/src/APIClient.cpp index a87d042..eb888fa 100644 --- a/src/APIClient.cpp +++ b/src/APIClient.cpp @@ -71,6 +71,7 @@ bool APIClient::uploadMeasurement(const String &filePath) { // Multipart body: head + file data + tail client.print(head); + ESP_LOGI(TAG_API, "DEBUG: Beginning file read loop"); uint8_t buffer[2048]; while (file.available()) { @@ -79,8 +80,10 @@ bool APIClient::uploadMeasurement(const String &filePath) { Watchdog::feed(); } + ESP_LOGI(TAG_API, "DEBUG: File read loop finished. Writing tail."); client.print(tail); file.close(); + ESP_LOGI(TAG_API, "DEBUG: Tail written. Waiting for response..."); // --- Parsowanie odpowiedzi --- int httpCode = 0; @@ -98,6 +101,7 @@ bool APIClient::uploadMeasurement(const String &filePath) { } Watchdog::feed(); } + ESP_LOGI(TAG_API, "DEBUG: Header parsing loop finished. httpCode: %d", httpCode); String responseBody = ""; while (client.available()) { diff --git a/src/UploadManager.cpp b/src/UploadManager.cpp index 4a74d3b..f23ee0a 100644 --- a/src/UploadManager.cpp +++ b/src/UploadManager.cpp @@ -63,7 +63,9 @@ void UploadManager::uploadFile(const String& filePath) { return; } + ESP_LOGI(TAG_UPLOAD, "DEBUG: Before apiClient.uploadMeasurement"); bool success = apiClient.uploadMeasurement(filePath); + ESP_LOGI(TAG_UPLOAD, "DEBUG: After apiClient.uploadMeasurement. Success: %d", success); if (success) { appendLog(filePath, "OK"); } else { @@ -79,11 +81,14 @@ void UploadManager::processPendingUploads() { if (WiFi.status() != WL_CONNECTED) return; ESP_LOGI(TAG_UPLOAD, "Checking for pending uploads..."); + ESP_LOGI(TAG_UPLOAD, "DEBUG: findHighestNumericDir()"); uint32_t highestDir = capture_.findHighestNumericDir(); + ESP_LOGI(TAG_UPLOAD, "DEBUG: highestDir: %u", highestDir); if (highestDir == 0) return; for (uint32_t d = 1; d <= highestDir; d++) { String path = capture_.dirPath(d); + ESP_LOGI(TAG_UPLOAD, "DEBUG: Scanning dir: %s", path.c_str()); File dir = SD.open(path); if (!dir || !dir.isDirectory()) { if(dir) dir.close(); @@ -100,7 +105,9 @@ void UploadManager::processPendingUploads() { if (childPath.endsWith(".wmt")) { if (!isAlreadyUploaded(childPath)) { ESP_LOGI(TAG_UPLOAD, "Found pending file: %s", childPath.c_str()); + ESP_LOGI(TAG_UPLOAD, "DEBUG: Calling uploadFile()"); uploadFile(childPath); + ESP_LOGI(TAG_UPLOAD, "DEBUG: Finished uploadFile(), delaying 1000ms"); delay(1000); } } diff --git a/src/main.cpp b/src/main.cpp index 206af86..dfc3f60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -347,6 +347,7 @@ void measure(){ Watchdog::feed(); if(!capture.isExit){ capture.printLastFileInfoSerial(); + ESP_LOGI(TAG_MAIN, "DEBUG: before readHeaderAndPrint"); capture.readHeaderAndPrint(capture.generateNextFilename().c_str()); ESP_LOGI(TAG_MAIN, "MEASURE FINISH"); } else { @@ -354,9 +355,12 @@ void measure(){ //runMeasure = false; } + ESP_LOGI(TAG_MAIN, "DEBUG: Checking WiFi status for upload"); if (config.connect && WiFi.status() == WL_CONNECTED) { ESP_LOGI(TAG_MAIN, "TRIGGER UPLOAD PENDING..."); + ESP_LOGI(TAG_MAIN, "DEBUG: Before uploadManager.processPendingUploads()"); uploadManager.processPendingUploads(); + ESP_LOGI(TAG_MAIN, "DEBUG: After uploadManager.processPendingUploads()"); } runMeasure = false;