From 97bce90ba63a558f892fd63a0941def6f7b459cb Mon Sep 17 00:00:00 2001 From: Emanuele Trabattoni Date: Wed, 8 Apr 2026 17:10:30 +0200 Subject: [PATCH] changed partition to littlefs, not working yet --- .../partitions/no_ota_10mb_littlefs.csv | 6 ++++++ RotaxMonitor/platformio.ini | 6 +++--- RotaxMonitor/src/datasave.cpp | 18 +++++++++--------- RotaxMonitor/src/datasave.h | 16 ++++++++-------- RotaxMonitor/src/main.cpp | 7 ++++--- 5 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 RotaxMonitor/partitions/no_ota_10mb_littlefs.csv diff --git a/RotaxMonitor/partitions/no_ota_10mb_littlefs.csv b/RotaxMonitor/partitions/no_ota_10mb_littlefs.csv new file mode 100644 index 0000000..b449d64 --- /dev/null +++ b/RotaxMonitor/partitions/no_ota_10mb_littlefs.csv @@ -0,0 +1,6 @@ +# ESP32 Partition Table +# Name, Type, SubType, Offset, Size +nvs, data, nvs, 0x9000, 0x4000 +phy_init, data, phy, 0xd000, 0x1000 +factory, app, factory, 0x10000, 0x300000 +littlefs, data, littlefs, 0x310000, 0xCF0000 diff --git a/RotaxMonitor/platformio.ini b/RotaxMonitor/platformio.ini index 9e5b1bf..e84e71b 100644 --- a/RotaxMonitor/platformio.ini +++ b/RotaxMonitor/platformio.ini @@ -10,8 +10,8 @@ [env:esp32-s3-devkitc1-n16r8] board = esp32-s3-devkitc1-n16r8 -board_build.partitions = partitions/no_ota_10mb_spiffs.csv -board_build.filesystem = spiffs +board_build.partitions = partitions/no_ota_10mb_littlefs.csv +board_build.filesystem = littlefs platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip framework = arduino lib_deps = @@ -21,7 +21,7 @@ lib_deps = me-no-dev/AsyncTCP@^3.3.2 me-no-dev/ESPAsyncWebServer@^3.6.0 upload_protocol = esptool -upload_port = COM8 +upload_port = COM4 upload_speed = 921600 monitor_port = COM4 monitor_speed = 921600 diff --git a/RotaxMonitor/src/datasave.cpp b/RotaxMonitor/src/datasave.cpp index 148c955..1f5111f 100644 --- a/RotaxMonitor/src/datasave.cpp +++ b/RotaxMonitor/src/datasave.cpp @@ -126,30 +126,30 @@ void save_history(const PSRAMVector &history, const std::file // Initialize SPIFFS if (!SAVE_HISTORY_TO_SPIFFS) return; - // auto spiffs_guard = SPIFFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted + // auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted - if (SPIFFS.totalBytes() - SPIFFS.usedBytes() < min_free) // check if at least 1MB is free for saving history + if (LittleFS.totalBytes() - LittleFS.usedBytes() < min_free) // check if at least 1MB is free for saving history { LOG_ERROR("Not enough space in SPIFFS to save history"); return; } std::filesystem::path file_path = file_name; - if (file_name.root_path() != "/spiffs") - file_path = std::filesystem::path("/spiffs") / file_name; + if (file_name.root_path() != "/littlefs") + file_path = std::filesystem::path("/littlefs") / file_name; auto save_flags = std::ios::out; - if (first_save && SPIFFS.exists(file_path.c_str())) + if (first_save && LittleFS.exists(file_path.c_str())) { first_save = false; save_flags |= std::ios::trunc; // overwrite existing file - SPIFFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS - LOG_INFO("Saving history to SPIFFS, new file:", file_path.c_str()); + LittleFS.remove(file_path.c_str()); // ensure file is removed before saving to avoid issues with appending to existing file in SPIFFS + LOG_INFO("Saving history to LittleFS, new file:", file_path.c_str()); } else { save_flags |= std::ios::app; // append to new file - LOG_INFO("Saving history to SPIFFS, appending to existing file:", file_path.c_str()); + LOG_INFO("Saving history to LittleFS, appending to existing file:", file_path.c_str()); } std::ofstream ofs(file_path, save_flags); @@ -197,5 +197,5 @@ void save_history(const PSRAMVector &history, const std::file } ofs.close(); - LOG_INFO("Ignition A history saved to SPIFFS, records written: ", history.size()); + LOG_INFO("Ignition A history saved to LittleFS, records written: ", history.size()); } diff --git a/RotaxMonitor/src/datasave.h b/RotaxMonitor/src/datasave.h index 9297f4c..6e8373e 100644 --- a/RotaxMonitor/src/datasave.h +++ b/RotaxMonitor/src/datasave.h @@ -4,7 +4,7 @@ // System Includes #include #include -#include +#include #include #include #include @@ -24,22 +24,22 @@ struct dataSaveParams const std::filesystem::path file_path; }; -class SPIFFSGuard +class LITTLEFSGuard { public: - SPIFFSGuard() + LITTLEFSGuard() { - if (!SPIFFS.begin(true)) + if (!LittleFS.begin(true)) { - LOG_ERROR("Failed to mount SPIFFS"); + LOG_ERROR("Failed to mount LittleFS"); } LOG_INFO("SPIFFS mounted successfully"); } - ~SPIFFSGuard() + ~LITTLEFSGuard() { - SPIFFS.end(); - LOG_INFO("SPIFFS unmounted successfully"); + LittleFS.end(); + LOG_INFO("LittleFS unmounted successfully"); } }; diff --git a/RotaxMonitor/src/main.cpp b/RotaxMonitor/src/main.cpp index 8185102..c7da43b 100644 --- a/RotaxMonitor/src/main.cpp +++ b/RotaxMonitor/src/main.cpp @@ -94,6 +94,7 @@ void loop() // global variables bool running = true; const uint32_t max_queue = 128; + const uint32_t filter_k = 10; PSRAMVector ignA_history_0(max_history); PSRAMVector ignA_history_1(max_history); auto *active_history = &ignA_history_0; @@ -221,15 +222,15 @@ void loop() int64_t last = esp_timer_get_time(); uint32_t missed_firings12 = 0; uint32_t missed_firings34 = 0; - ignitionBoxStatusAverage ignA_avg(max_queue); // moving average calculator for ignition box A with a window of 100 samples + ignitionBoxStatusAverage ignA_avg(filter_k); // moving average calculator for ignition box A with a window of 100 samples AsyncWebServer server(80); AsyncWebSocket ws("/ws"); ws.onEvent(onWsEvent); server.addHandler(&ws); - auto spiffs_guard = SPIFFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted - server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html"); + auto spiffs_guard = LITTLEFSGuard(); // use RAII guard to ensure SPIFFS is properly mounted and unmounted + server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html"); server.begin(); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)