From 51c31dff116e65ab1f722f2cf287a75a70243a64 Mon Sep 17 00:00:00 2001 From: cotestatnt Date: Sun, 7 Jan 2024 10:48:08 +0100 Subject: [PATCH] ESP8266 LittleFS error with PROGMEM --- examples/customHTML/.vscode/settings.json | 3 ++- examples/customHTML/customHTML.ino | 2 +- src/AsyncFsWebServer.cpp | 15 +++++++++------ src/AsyncFsWebServer.h | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/customHTML/.vscode/settings.json b/examples/customHTML/.vscode/settings.json index 930ff050..02e74bf4 100644 --- a/examples/customHTML/.vscode/settings.json +++ b/examples/customHTML/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { - "*.tcc": "cpp" + "*.tcc": "cpp", + "ostream": "cpp" } } \ No newline at end of file diff --git a/examples/customHTML/customHTML.ino b/examples/customHTML/customHTML.ino index fbf20a2b..46076502 100644 --- a/examples/customHTML/customHTML.ino +++ b/examples/customHTML/customHTML.ino @@ -212,7 +212,7 @@ void setup() { // Add custom page title to /setup server.setSetupPageTitle("Test setup page"); // Add custom logo to /setup page with custom size - server.setLogoBase64(base64_logo, "128", "128", /*overwite file*/ true); + server.setLogoBase64(base64_logo, "128", "128", /*overwite file*/ false); // Enable ACE FS file web editor and add FS info callback fucntion server.enableFsCodeEditor(); diff --git a/src/AsyncFsWebServer.cpp b/src/AsyncFsWebServer.cpp index d8f1a26a..33bc354d 100644 --- a/src/AsyncFsWebServer.cpp +++ b/src/AsyncFsWebServer.cpp @@ -266,24 +266,26 @@ void AsyncFsWebServer::setLogoBase64(const char* logo, const char* width, const strcat(filename, "_"); strcat(filename, height); strcat(filename, ".txt"); + optionToFile(filename, logo, overwrite); addOption("img-logo", filename); } bool AsyncFsWebServer::optionToFile(const char* filename, const char* str, bool overWrite) { // Check if file is already saved - File file = m_filesystem->open(filename, "r"); - if (file && !overWrite) { - file.close(); + if (m_filesystem->exists(filename) && !overWrite) { return true; } // Create or overwrite option file else { - file.close(); - file = m_filesystem->open(filename, "w"); - + File file = m_filesystem->open(filename, "w"); if (file) { + #if defined(ESP8266) + String _str = str; + file.print(_str); + #else file.print(str); + #endif file.close(); log_debug("File %s saved", filename); return true; @@ -306,6 +308,7 @@ void AsyncFsWebServer::addSource(const char* source, const char* tag, bool overW path += ".css"; else if (strstr(tag, "javascript") != NULL) path += ".js"; + optionToFile(path.c_str(), source, overWrite); addOption(tag, path.c_str(), false); } diff --git a/src/AsyncFsWebServer.h b/src/AsyncFsWebServer.h index 4593299a..00ce8ccc 100644 --- a/src/AsyncFsWebServer.h +++ b/src/AsyncFsWebServer.h @@ -30,7 +30,7 @@ #define CONFIG_FILE "/config.json" #define DBG_OUTPUT_PORT Serial -#define LOG_LEVEL 3 // (0 disable, 1 error, 2 info, 3 debug) +#define LOG_LEVEL 2 // (0 disable, 1 error, 2 info, 3 debug) #include "SerialLog.h" #include "CaptiverPortal.hpp"