From 3fe412d9cdbde9c43aa21a3119a3c1b222cca83b Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Wed, 29 Jul 2020 20:55:25 +0800 Subject: [PATCH 01/15] move SPIFFS to LittleFS for ESP8266 --- examples/IRMQTTServer/IRMQTTServer.ino | 23 ++++++++++++++++++++-- examples/Web-AC-control/Web-AC-control.ino | 12 +++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index 6bf504b0e..ef87458ec 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -333,7 +333,11 @@ #include "IRMQTTServer.h" #include +#if defined(ESP8266) +#include +#else #include +#endif #include #if defined(ESP8266) #include @@ -521,11 +525,19 @@ void saveWifiConfigCallback(void) { // A boolean indicating success or failure. bool mountSpiffs(void) { debug("Mounting SPIFFS..."); - if (SPIFFS.begin()) return true; // We mounted it okay. +#if defined(ESP8266) + if (LittleFS.begin()) return true; // We mounted it okay. +#else + if (SPIFFS.begin()) return true; +#endif // We failed the first time. debug("Failed to mount SPIFFS!\nFormatting SPIFFS and trying again..."); SPIFFS.format(); +#if defined(ESP8266) + if (!LittleFS.begin()) { // Did we fail? +#else if (!SPIFFS.begin()) { // Did we fail? +#endif debug("DANGER: Failed to mount SPIFFS even after formatting!"); delay(10000); // Make sure the debug message doesn't just float by. return false; @@ -556,7 +568,11 @@ bool saveConfig(void) { } if (mountSpiffs()) { +#if defined(ESP8266) + File configFile = LittleFS.open(kConfigFile, "w"); +#else File configFile = SPIFFS.open(kConfigFile, "w"); +#endif if (!configFile) { debug("Failed to open config file for writing."); } else { @@ -577,8 +593,11 @@ bool loadConfigFile(void) { debug("mounted the file system"); if (SPIFFS.exists(kConfigFile)) { debug("config file exists"); - +#if defined(ESP8266) + File configFile = LittleFS.open(kConfigFile, "r"); +#else File configFile = SPIFFS.open(kConfigFile, "r"); +#endif if (configFile) { debug("Opened config file"); size_t size = configFile.size(); diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index ac02bdc59..ad704cb24 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -6,7 +6,11 @@ is selected (required for Coolix). */ +#if defined(ESP8266) +#include +#else #include +#endif #if defined(ESP8266) #include #include @@ -83,7 +87,11 @@ bool handleFileRead(String path) { // If the file exists, either as a compressed archive, or normal if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available path += ".gz"; // Use the compressed verion +#if defined(ESP8266) + File file = LittleFS.open(path, "r"); +#else File file = SPIFFS.open(path, "r"); +#endif // Open the file server.streamFile(file, contentType); // Send it to the client @@ -113,7 +121,11 @@ void handleFileUpload() { // upload a new file to the SPIFFS String filename = upload.filename; if (!filename.startsWith("/")) filename = "/" + filename; // Serial.print("handleFileUpload Name: "); //Serial.println(filename); +#if defined(ESP8266) + fsUploadFile = LittleFS.open(filename, "w"); +#else fsUploadFile = SPIFFS.open(filename, "w"); +#endif // Open the file for writing in SPIFFS (create if it doesn't exist) filename = String(); } else if (upload.status == UPLOAD_FILE_WRITE) { From 97762ec20a2f51b19ef3a7f29eee122b5aab16ab Mon Sep 17 00:00:00 2001 From: ymiao Date: Fri, 31 Jul 2020 10:17:38 +0800 Subject: [PATCH 02/15] add FILESYSTEM warning --- examples/IRMQTTServer/IRMQTTServer.ino | 65 +++++++++++----------- examples/Web-AC-control/Web-AC-control.ino | 41 ++++++++------ 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index ef87458ec..23fdb8f64 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -38,7 +38,7 @@ * o You MUST change to have the following (or larger) value: * (with REPORT_RAW_UNKNOWNS 1024 or more is recommended) * #define MQTT_MAX_PACKET_SIZE 768 - * o Use the smallest non-zero SPIFFS size you can for your board. + * o Use the smallest non-zero FILESYSTEM size you can for your board. * (See the Tools -> Flash Size menu) * * - PlatformIO IDE: @@ -336,7 +336,7 @@ #if defined(ESP8266) #include #else -#include +#include #endif #include #if defined(ESP8266) @@ -348,7 +348,6 @@ #include #include #include -#include #include #endif // ESP32 #include @@ -385,6 +384,20 @@ using irutils::msToString; #endif // REPORT_VCC // Globals + +// Uncomment one of the following to manually override what type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally saved configuration data to be lost. +// #define FILESYSTEM SPIFFS +// #define FILESYSTEM LittleFS +#ifndef FILESYSTEM +// Set the default filesystem if none was specified. +#if defined(ESP8266) +#define FILESYSTEM LittleFS +#else +#define FILESYSTEM SPIFFS +#endif // defined(ESP8266) +#endif // FILESYSTEM + #if defined(ESP8266) ESP8266WebServer server(kHttpPort); #endif // ESP8266 @@ -519,26 +532,18 @@ void saveWifiConfigCallback(void) { flagSaveWifiConfig = true; } -// Forcibly mount the SPIFFS. Formatting the SPIFFS if needed. +// Forcibly mount the FILESYSTEM. Formatting the FILESYSTEM if needed. // // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { - debug("Mounting SPIFFS..."); -#if defined(ESP8266) - if (LittleFS.begin()) return true; // We mounted it okay. -#else - if (SPIFFS.begin()) return true; -#endif + debug("Mounting FILESYSTEM..."); + if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. - debug("Failed to mount SPIFFS!\nFormatting SPIFFS and trying again..."); - SPIFFS.format(); -#if defined(ESP8266) - if (!LittleFS.begin()) { // Did we fail? -#else - if (!SPIFFS.begin()) { // Did we fail? -#endif - debug("DANGER: Failed to mount SPIFFS even after formatting!"); + debug("Failed to mount FILESYSTEM!\nFormatting FILESYSTEM and trying again..."); + FILESYSTEM.format(); + if (!FILESYSTEM.begin()) { // Did we fail? + debug("DANGER: Failed to mount FILESYSTEM even after formatting!"); delay(10000); // Make sure the debug message doesn't just float by. return false; } @@ -568,11 +573,7 @@ bool saveConfig(void) { } if (mountSpiffs()) { -#if defined(ESP8266) - File configFile = LittleFS.open(kConfigFile, "w"); -#else - File configFile = SPIFFS.open(kConfigFile, "w"); -#endif + File configFile = FILESYSTEM.open(kConfigFile, "w"); if (!configFile) { debug("Failed to open config file for writing."); } else { @@ -582,7 +583,7 @@ bool saveConfig(void) { debug("Finished writing config file."); success = true; } - SPIFFS.end(); + FILESYSTEM.end(); } return success; } @@ -591,13 +592,9 @@ bool loadConfigFile(void) { bool success = false; if (mountSpiffs()) { debug("mounted the file system"); - if (SPIFFS.exists(kConfigFile)) { + if (FILESYSTEM.exists(kConfigFile)) { debug("config file exists"); -#if defined(ESP8266) - File configFile = LittleFS.open(kConfigFile, "r"); -#else - File configFile = SPIFFS.open(kConfigFile, "r"); -#endif + File configFile = FILESYSTEM.open(kConfigFile, "r"); if (configFile) { debug("Opened config file"); size_t size = configFile.size(); @@ -638,8 +635,8 @@ bool loadConfigFile(void) { } else { debug("Config file doesn't exist!"); } - debug("Unmounting SPIFFS."); - SPIFFS.end(); + debug("Unmounting FILESYSTEM."); + FILESYSTEM.end(); } return success; } @@ -1473,8 +1470,8 @@ void handleReset(void) { #endif // MQTT_ENABLE if (mountSpiffs()) { debug("Removing JSON config file"); - SPIFFS.remove(kConfigFile); - SPIFFS.end(); + FILESYSTEM.remove(kConfigFile); + FILESYSTEM.end(); } delay(1000); debug("Reseting wifiManager's settings."); diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index ad704cb24..5f89e8d3f 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -9,7 +9,7 @@ #if defined(ESP8266) #include #else -#include +#include #endif #if defined(ESP8266) #include @@ -21,7 +21,6 @@ #include #include #include -#include #include #endif // ESP32 #include @@ -34,6 +33,20 @@ #include // replace library based on your AC unit model, check https://github.com/crankyoldgit/IRremoteESP8266 +// Uncomment one of the following to manually override what type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally saved configuration data to be lost. +// #define FILESYSTEM (SPIFFS) +// #define FILESYSTEM LittleFS + +#ifndef FILESYSTEM +// Set the default filesystem if none was specified. +#if defined(ESP8266) +#define FILESYSTEM LittleFS +#else +#define FILESYSTEM SPIFFS +#endif +#endif // FILESYSTEM + #define AUTO_MODE kCoolixAuto #define COOL_MODE kCoolixCool #define DRY_MODE kCoolixDry @@ -83,15 +96,11 @@ bool handleFileRead(String path) { String contentType = getContentType(path); // Get the MIME type String pathWithGz = path + ".gz"; - if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { + if (FILESYSTEM.exists(pathWithGz) || FILESYSTEM.exists(path)) { // If the file exists, either as a compressed archive, or normal - if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available + if (FILESYSTEM.exists(pathWithGz)) // If there's a compressed version available path += ".gz"; // Use the compressed verion -#if defined(ESP8266) - File file = LittleFS.open(path, "r"); -#else - File file = SPIFFS.open(path, "r"); -#endif + File file = FILESYSTEM.open(path, "r"); // Open the file server.streamFile(file, contentType); // Send it to the client @@ -115,18 +124,14 @@ String getContentType(String filename) { return "text/plain"; } -void handleFileUpload() { // upload a new file to the SPIFFS +void handleFileUpload() { // upload a new file to the FILESYSTEM HTTPUpload& upload = server.upload(); if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; if (!filename.startsWith("/")) filename = "/" + filename; // Serial.print("handleFileUpload Name: "); //Serial.println(filename); -#if defined(ESP8266) - fsUploadFile = LittleFS.open(filename, "w"); -#else - fsUploadFile = SPIFFS.open(filename, "w"); -#endif - // Open the file for writing in SPIFFS (create if it doesn't exist) + fsUploadFile = FILESYSTEM.open(filename, "w"); + // Open the file for writing in FILESYSTEM (create if it doesn't exist) filename = String(); } else if (upload.status == UPLOAD_FILE_WRITE) { if (fsUploadFile) @@ -174,7 +179,7 @@ void setup() { // Serial.println("mounting FS..."); - if (!SPIFFS.begin()) { + if (!FILESYSTEM.begin()) { // Serial.println("Failed to mount file system"); return; } @@ -299,7 +304,7 @@ void setup() { ESP.restart(); }); - server.serveStatic("/", SPIFFS, "/", "max-age=86400"); + server.serveStatic("/", FILESYSTEM, "/", "max-age=86400"); server.onNotFound(handleNotFound); From b5f62417251c335adf9631d59b034ebf218888be Mon Sep 17 00:00:00 2001 From: ymiao Date: Fri, 31 Jul 2020 10:43:08 +0800 Subject: [PATCH 03/15] make lines <= 80 characters long --- examples/IRMQTTServer/IRMQTTServer.ino | 9 ++++++--- examples/Web-AC-control/Web-AC-control.ino | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index 23fdb8f64..9e2b438ea 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -385,8 +385,10 @@ using irutils::msToString; // Globals -// Uncomment one of the following to manually override what type of persistent storage is used. -// Warning: Changing filesystems will cause all previous locally saved configuration data to be lost. +// Uncomment one of the following to manually override what +// type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally +// saved configuration data to be lost. // #define FILESYSTEM SPIFFS // #define FILESYSTEM LittleFS #ifndef FILESYSTEM @@ -540,7 +542,8 @@ bool mountSpiffs(void) { debug("Mounting FILESYSTEM..."); if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. - debug("Failed to mount FILESYSTEM!\nFormatting FILESYSTEM and trying again..."); + debug("Failed to mount FILESYSTEM!\n" + "Formatting FILESYSTEM and trying again..."); FILESYSTEM.format(); if (!FILESYSTEM.begin()) { // Did we fail? debug("DANGER: Failed to mount FILESYSTEM even after formatting!"); diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index 5f89e8d3f..ef04c9b5b 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -33,9 +33,11 @@ #include // replace library based on your AC unit model, check https://github.com/crankyoldgit/IRremoteESP8266 -// Uncomment one of the following to manually override what type of persistent storage is used. -// Warning: Changing filesystems will cause all previous locally saved configuration data to be lost. -// #define FILESYSTEM (SPIFFS) +// Uncomment one of the following to manually override what +// type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally +// saved configuration data to be lost. +// #define FILESYSTEM SPIFFS // #define FILESYSTEM LittleFS #ifndef FILESYSTEM From 40da90731a3e2002a17d760afb73acff96ef88a0 Mon Sep 17 00:00:00 2001 From: ymiao Date: Fri, 31 Jul 2020 11:00:12 +0800 Subject: [PATCH 04/15] make lines <= 80 characters long --- examples/Web-AC-control/Web-AC-control.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index ef04c9b5b..a6e11f682 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -100,7 +100,8 @@ bool handleFileRead(String path) { String pathWithGz = path + ".gz"; if (FILESYSTEM.exists(pathWithGz) || FILESYSTEM.exists(path)) { // If the file exists, either as a compressed archive, or normal - if (FILESYSTEM.exists(pathWithGz)) // If there's a compressed version available + // If there's a compressed version available + if (FILESYSTEM.exists(pathWithGz)) path += ".gz"; // Use the compressed verion File file = FILESYSTEM.open(path, "r"); // Open the file From 73013c3775ddb2f63056d9ead3b7adf86e0eab87 Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Sun, 2 Aug 2020 21:47:32 +0800 Subject: [PATCH 05/15] no message --- examples/Web-AC-control/Web-AC-control.ino | 20 +++++++++--------- .../{upload => data}/favicon.ico | Bin .../{upload => data}/level_1_off.svg | 0 .../{upload => data}/level_1_on.svg | 0 .../{upload => data}/level_2_off.svg | 0 .../{upload => data}/level_2_on.svg | 0 .../{upload => data}/level_3_off.svg | 0 .../{upload => data}/level_3_on.svg | 0 .../{upload => data}/level_4_off.svg | 0 .../{upload => data}/level_4_on.svg | 0 .../Web-AC-control/{upload => data}/ui.html | 0 .../Web-AC-control/{upload => data}/ui.js | 0 examples/Web-AC-control/platformio.ini | 11 +++++----- 13 files changed, 16 insertions(+), 15 deletions(-) rename examples/Web-AC-control/{upload => data}/favicon.ico (100%) rename examples/Web-AC-control/{upload => data}/level_1_off.svg (100%) rename examples/Web-AC-control/{upload => data}/level_1_on.svg (100%) rename examples/Web-AC-control/{upload => data}/level_2_off.svg (100%) rename examples/Web-AC-control/{upload => data}/level_2_on.svg (100%) rename examples/Web-AC-control/{upload => data}/level_3_off.svg (100%) rename examples/Web-AC-control/{upload => data}/level_3_on.svg (100%) rename examples/Web-AC-control/{upload => data}/level_4_off.svg (100%) rename examples/Web-AC-control/{upload => data}/level_4_on.svg (100%) rename examples/Web-AC-control/{upload => data}/ui.html (100%) rename examples/Web-AC-control/{upload => data}/ui.js (100%) diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index ad704cb24..35fc1ad7c 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -77,7 +77,7 @@ WebServer server(80); bool handleFileRead(String path) { // send the right file to the client (if it exists) - // Serial.println("handleFileRead: " + path); + Serial.println("handleFileRead: " + path); if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file String contentType = getContentType(path); @@ -97,10 +97,10 @@ bool handleFileRead(String path) { // Send it to the client file.close(); // Close the file again - // Serial.println(String("\tSent file: ") + path); + Serial.println(String("\tSent file: ") + path); return true; } - // Serial.println(String("\tFile Not Found: ") + path); + Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false return false; } @@ -120,7 +120,7 @@ void handleFileUpload() { // upload a new file to the SPIFFS if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; if (!filename.startsWith("/")) filename = "/" + filename; - // Serial.print("handleFileUpload Name: "); //Serial.println(filename); + Serial.print("handleFileUpload Name: "); //Serial.println(filename); #if defined(ESP8266) fsUploadFile = LittleFS.open(filename, "w"); #else @@ -137,8 +137,8 @@ void handleFileUpload() { // upload a new file to the SPIFFS // If the file was successfully created fsUploadFile.close(); // Close the file again - // Serial.print("handleFileUpload Size: "); - // Serial.println(upload.totalSize); + Serial.print("handleFileUpload Size: "); + Serial.println(upload.totalSize); server.sendHeader("Location", "/success.html"); // Redirect the client to the success page server.send(303); @@ -165,17 +165,17 @@ void handleNotFound() { } void setup() { - // Serial.begin(115200); - // Serial.println(); + Serial.begin(115200); + Serial.println(); ac.begin(); delay(1000); - // Serial.println("mounting FS..."); + Serial.println("mounting FS..."); if (!SPIFFS.begin()) { - // Serial.println("Failed to mount file system"); + Serial.println("Failed to mount file system"); return; } diff --git a/examples/Web-AC-control/upload/favicon.ico b/examples/Web-AC-control/data/favicon.ico similarity index 100% rename from examples/Web-AC-control/upload/favicon.ico rename to examples/Web-AC-control/data/favicon.ico diff --git a/examples/Web-AC-control/upload/level_1_off.svg b/examples/Web-AC-control/data/level_1_off.svg similarity index 100% rename from examples/Web-AC-control/upload/level_1_off.svg rename to examples/Web-AC-control/data/level_1_off.svg diff --git a/examples/Web-AC-control/upload/level_1_on.svg b/examples/Web-AC-control/data/level_1_on.svg similarity index 100% rename from examples/Web-AC-control/upload/level_1_on.svg rename to examples/Web-AC-control/data/level_1_on.svg diff --git a/examples/Web-AC-control/upload/level_2_off.svg b/examples/Web-AC-control/data/level_2_off.svg similarity index 100% rename from examples/Web-AC-control/upload/level_2_off.svg rename to examples/Web-AC-control/data/level_2_off.svg diff --git a/examples/Web-AC-control/upload/level_2_on.svg b/examples/Web-AC-control/data/level_2_on.svg similarity index 100% rename from examples/Web-AC-control/upload/level_2_on.svg rename to examples/Web-AC-control/data/level_2_on.svg diff --git a/examples/Web-AC-control/upload/level_3_off.svg b/examples/Web-AC-control/data/level_3_off.svg similarity index 100% rename from examples/Web-AC-control/upload/level_3_off.svg rename to examples/Web-AC-control/data/level_3_off.svg diff --git a/examples/Web-AC-control/upload/level_3_on.svg b/examples/Web-AC-control/data/level_3_on.svg similarity index 100% rename from examples/Web-AC-control/upload/level_3_on.svg rename to examples/Web-AC-control/data/level_3_on.svg diff --git a/examples/Web-AC-control/upload/level_4_off.svg b/examples/Web-AC-control/data/level_4_off.svg similarity index 100% rename from examples/Web-AC-control/upload/level_4_off.svg rename to examples/Web-AC-control/data/level_4_off.svg diff --git a/examples/Web-AC-control/upload/level_4_on.svg b/examples/Web-AC-control/data/level_4_on.svg similarity index 100% rename from examples/Web-AC-control/upload/level_4_on.svg rename to examples/Web-AC-control/data/level_4_on.svg diff --git a/examples/Web-AC-control/upload/ui.html b/examples/Web-AC-control/data/ui.html similarity index 100% rename from examples/Web-AC-control/upload/ui.html rename to examples/Web-AC-control/data/ui.html diff --git a/examples/Web-AC-control/upload/ui.js b/examples/Web-AC-control/data/ui.js similarity index 100% rename from examples/Web-AC-control/upload/ui.js rename to examples/Web-AC-control/data/ui.js diff --git a/examples/Web-AC-control/platformio.ini b/examples/Web-AC-control/platformio.ini index 19ff9c277..7714b5454 100644 --- a/examples/Web-AC-control/platformio.ini +++ b/examples/Web-AC-control/platformio.ini @@ -10,6 +10,7 @@ monitor_speed = 115200 build_flags = ; -D_IR_LOCALE_=en-AU [common] +ldscript_4m = eagle.flash.4m3m.ld lib_deps_builtin = lib_deps_external = ArduinoJson@>=6.0 @@ -30,8 +31,8 @@ lib_deps_external = platform = espressif8266 board = nodemcuv2 lib_deps = ${common_esp8266.lib_deps_external} - -[env:esp32dev] -platform = espressif32 -board = esp32dev -lib_deps = ${common_esp32.lib_deps_external} +board_build.ldscript = ${common.ldscript_4m} +; [env:esp32dev] +; platform = espressif32 +; board = esp32dev +; lib_deps = ${common_esp32.lib_deps_external} From 7a6b70c95d11f51b2e9fefe257d0d51aba06a92f Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 4 Aug 2020 20:06:29 +0800 Subject: [PATCH 06/15] Move SPIFFS to LittleFS for ESP8266(#1182) --- examples/IRMQTTServer/IRMQTTServer.h | 20 +++++++- examples/IRMQTTServer/IRMQTTServer.ino | 55 ++++++++-------------- examples/Web-AC-control/Web-AC-control.h | 31 ++++++++++++ examples/Web-AC-control/Web-AC-control.ino | 37 +-------------- 4 files changed, 70 insertions(+), 73 deletions(-) create mode 100644 examples/Web-AC-control/Web-AC-control.h diff --git a/examples/IRMQTTServer/IRMQTTServer.h b/examples/IRMQTTServer/IRMQTTServer.h index b283e330f..af2fc8e17 100644 --- a/examples/IRMQTTServer/IRMQTTServer.h +++ b/examples/IRMQTTServer/IRMQTTServer.h @@ -4,7 +4,11 @@ */ #ifndef EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ #define EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ - +#if defined(ESP8266) +#include +#else +#include +#endif #if defined(ESP8266) #include #endif // ESP8266 @@ -27,6 +31,20 @@ #define EXAMPLES_ENABLE true #endif // EXAMPLES_ENABLE +// Uncomment one of the following to manually override what +// type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally +// saved configuration data to be lost. +// #define FILE_SYSTEM SPIFFS +// #define FILE_SYSTEM LittleFS +#ifndef FILE_SYSTEM +// Set the default filesystem if none was specified. +#ifdef ESP8266 +#define FILE_SYSTEM LittleFS +#else +#define FILE_SYSTEM SPIFFS +#endif // defined(ESP8266) +#endif // FILE_SYSTEM // ---------------------- Board Related Settings ------------------------------- // NOTE: Make sure you set your Serial Monitor to the same speed. #define BAUD_RATE 115200 // Serial port Baud rate. diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index 9e2b438ea..d01d457ef 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -38,7 +38,7 @@ * o You MUST change to have the following (or larger) value: * (with REPORT_RAW_UNKNOWNS 1024 or more is recommended) * #define MQTT_MAX_PACKET_SIZE 768 - * o Use the smallest non-zero FILESYSTEM size you can for your board. + * o Use the smallest non-zero FILE_SYSTEM size you can for your board. * (See the Tools -> Flash Size menu) * * - PlatformIO IDE: @@ -333,11 +333,7 @@ #include "IRMQTTServer.h" #include -#if defined(ESP8266) -#include -#else -#include -#endif + #include #if defined(ESP8266) #include @@ -385,20 +381,7 @@ using irutils::msToString; // Globals -// Uncomment one of the following to manually override what -// type of persistent storage is used. -// Warning: Changing filesystems will cause all previous locally -// saved configuration data to be lost. -// #define FILESYSTEM SPIFFS -// #define FILESYSTEM LittleFS -#ifndef FILESYSTEM -// Set the default filesystem if none was specified. -#if defined(ESP8266) -#define FILESYSTEM LittleFS -#else -#define FILESYSTEM SPIFFS -#endif // defined(ESP8266) -#endif // FILESYSTEM + #if defined(ESP8266) ESP8266WebServer server(kHttpPort); @@ -534,19 +517,19 @@ void saveWifiConfigCallback(void) { flagSaveWifiConfig = true; } -// Forcibly mount the FILESYSTEM. Formatting the FILESYSTEM if needed. +// Forcibly mount the FILE_SYSTEM. Formatting the FILE_SYSTEM if needed. // // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { - debug("Mounting FILESYSTEM..."); - if (FILESYSTEM.begin()) return true; // We mounted it okay. + debug("Mounting FILE_SYSTEM..."); + if (FILE_SYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. - debug("Failed to mount FILESYSTEM!\n" - "Formatting FILESYSTEM and trying again..."); - FILESYSTEM.format(); - if (!FILESYSTEM.begin()) { // Did we fail? - debug("DANGER: Failed to mount FILESYSTEM even after formatting!"); + debug("Failed to mount FILE_SYSTEM!\n" + "Formatting FILE_SYSTEM and trying again..."); + FILE_SYSTEM.format(); + if (!FILE_SYSTEM.begin()) { // Did we fail? + debug("DANGER: Failed to mount FILE_SYSTEM even after formatting!"); delay(10000); // Make sure the debug message doesn't just float by. return false; } @@ -576,7 +559,7 @@ bool saveConfig(void) { } if (mountSpiffs()) { - File configFile = FILESYSTEM.open(kConfigFile, "w"); + File configFile = FILE_SYSTEM.open(kConfigFile, "w"); if (!configFile) { debug("Failed to open config file for writing."); } else { @@ -586,7 +569,7 @@ bool saveConfig(void) { debug("Finished writing config file."); success = true; } - FILESYSTEM.end(); + FILE_SYSTEM.end(); } return success; } @@ -595,9 +578,9 @@ bool loadConfigFile(void) { bool success = false; if (mountSpiffs()) { debug("mounted the file system"); - if (FILESYSTEM.exists(kConfigFile)) { + if (FILE_SYSTEM.exists(kConfigFile)) { debug("config file exists"); - File configFile = FILESYSTEM.open(kConfigFile, "r"); + File configFile = FILE_SYSTEM.open(kConfigFile, "r"); if (configFile) { debug("Opened config file"); size_t size = configFile.size(); @@ -638,8 +621,8 @@ bool loadConfigFile(void) { } else { debug("Config file doesn't exist!"); } - debug("Unmounting FILESYSTEM."); - FILESYSTEM.end(); + debug("Unmounting FILE_SYSTEM."); + FILE_SYSTEM.end(); } return success; } @@ -1473,8 +1456,8 @@ void handleReset(void) { #endif // MQTT_ENABLE if (mountSpiffs()) { debug("Removing JSON config file"); - FILESYSTEM.remove(kConfigFile); - FILESYSTEM.end(); + FILE_SYSTEM.remove(kConfigFile); + FILE_SYSTEM.end(); } delay(1000); debug("Reseting wifiManager's settings."); diff --git a/examples/Web-AC-control/Web-AC-control.h b/examples/Web-AC-control/Web-AC-control.h new file mode 100644 index 000000000..e6c533619 --- /dev/null +++ b/examples/Web-AC-control/Web-AC-control.h @@ -0,0 +1,31 @@ +/* Copyright 2019 Motea Marius + + This example code will create a webserver that will provide basic control to AC units using the web application + build with javascript/css. User config zone need to be updated if a different class than Collix need to be used. + Javasctipt file may also require minor changes as in current version it will not allow to set fan speed if Auto mode + is selected (required for Coolix). + +*/ +#ifndef EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ +#define EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ +#if defined(ESP8266) +#include +#else +#include +#endif + +// Uncomment one of the following to manually override what +// type of persistent storage is used. +// Warning: Changing filesystems will cause all previous locally +// saved configuration data to be lost. +// #define FILESYSTEM SPIFFS +// #define FILESYSTEM LittleFS +#ifndef FILESYSTEM +// Set the default filesystem if none was specified. +#ifdef ESP8266 +#define FILESYSTEM LittleFS +#else +#define FILESYSTEM SPIFFS +#endif // defined(ESP8266) +#endif // FILESYSTEM +#endif // EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ \ No newline at end of file diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index d22ed018d..decd48819 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -6,11 +6,7 @@ is selected (required for Coolix). */ -#if defined(ESP8266) -#include -#else -#include -#endif +#include "Web-AC-control.h" #if defined(ESP8266) #include #include @@ -33,22 +29,6 @@ #include // replace library based on your AC unit model, check https://github.com/crankyoldgit/IRremoteESP8266 -// Uncomment one of the following to manually override what -// type of persistent storage is used. -// Warning: Changing filesystems will cause all previous locally -// saved configuration data to be lost. -// #define FILESYSTEM SPIFFS -// #define FILESYSTEM LittleFS - -#ifndef FILESYSTEM -// Set the default filesystem if none was specified. -#if defined(ESP8266) -#define FILESYSTEM LittleFS -#else -#define FILESYSTEM SPIFFS -#endif -#endif // FILESYSTEM - #define AUTO_MODE kCoolixAuto #define COOL_MODE kCoolixCool #define DRY_MODE kCoolixDry @@ -132,19 +112,9 @@ void handleFileUpload() { // upload a new file to the FILESYSTEM if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; if (!filename.startsWith("/")) filename = "/" + filename; -<<<<<<< HEAD - Serial.print("handleFileUpload Name: "); //Serial.println(filename); -#if defined(ESP8266) - fsUploadFile = LittleFS.open(filename, "w"); -#else - fsUploadFile = SPIFFS.open(filename, "w"); -#endif - // Open the file for writing in SPIFFS (create if it doesn't exist) -======= // Serial.print("handleFileUpload Name: "); //Serial.println(filename); fsUploadFile = FILESYSTEM.open(filename, "w"); // Open the file for writing in FILESYSTEM (create if it doesn't exist) ->>>>>>> 40da90731a3e2002a17d760afb73acff96ef88a0 filename = String(); } else if (upload.status == UPLOAD_FILE_WRITE) { if (fsUploadFile) @@ -192,13 +162,8 @@ void setup() { Serial.println("mounting FS..."); -<<<<<<< HEAD - if (!SPIFFS.begin()) { - Serial.println("Failed to mount file system"); -======= if (!FILESYSTEM.begin()) { // Serial.println("Failed to mount file system"); ->>>>>>> 40da90731a3e2002a17d760afb73acff96ef88a0 return; } From 1da58168b2c324b9df3800616560a30a3296ec1a Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 4 Aug 2020 20:33:08 +0800 Subject: [PATCH 07/15] [fix]: wrong format --- examples/Web-AC-control/Web-AC-control.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index decd48819..c1c2ebd13 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -72,7 +72,7 @@ WebServer server(80); bool handleFileRead(String path) { // send the right file to the client (if it exists) - Serial.println("handleFileRead: " + path); + Serial.println("handleFileRead: " + path); if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file String contentType = getContentType(path); From 361b1523a4a3ab5b5fdf4797aca543eac4c02c47 Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 4 Aug 2020 20:51:23 +0800 Subject: [PATCH 08/15] [fix]: fix error format --- examples/Web-AC-control/Web-AC-control.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Web-AC-control/Web-AC-control.h b/examples/Web-AC-control/Web-AC-control.h index e6c533619..51c7c8f26 100644 --- a/examples/Web-AC-control/Web-AC-control.h +++ b/examples/Web-AC-control/Web-AC-control.h @@ -6,8 +6,8 @@ is selected (required for Coolix). */ -#ifndef EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ -#define EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ +#ifndef EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ +#define EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ #if defined(ESP8266) #include #else @@ -28,4 +28,4 @@ #define FILESYSTEM SPIFFS #endif // defined(ESP8266) #endif // FILESYSTEM -#endif // EXAMPLES_WEBACCONTROL_WEBACCONTROL_H_ \ No newline at end of file +#endif // EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ \ No newline at end of file From 2228f4bb74cec3b78408f3d247ec6dd733dbd6c7 Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 4 Aug 2020 21:04:47 +0800 Subject: [PATCH 09/15] [fix] fix error format --- examples/Web-AC-control/Web-AC-control.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Web-AC-control/Web-AC-control.h b/examples/Web-AC-control/Web-AC-control.h index 51c7c8f26..755761df2 100644 --- a/examples/Web-AC-control/Web-AC-control.h +++ b/examples/Web-AC-control/Web-AC-control.h @@ -6,8 +6,8 @@ is selected (required for Coolix). */ -#ifndef EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ -#define EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ +#ifndef EXAMPLES_WEB_AC_CONTROL_WEB_AC_CONTROL_H_ +#define EXAMPLES_WEB_AC_CONTROL_WEB_AC_CONTROL_H_ #if defined(ESP8266) #include #else @@ -28,4 +28,4 @@ #define FILESYSTEM SPIFFS #endif // defined(ESP8266) #endif // FILESYSTEM -#endif // EXAMPLES_WEB_AC_CONTROL_WEBACCONTROL_H_ \ No newline at end of file +#endif // EXAMPLES_WEB_AC_CONTROL_WEB_AC_CONTROL_H_ From 6976880a366f94c57048190c20cdd7f699135e3b Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 4 Aug 2020 21:22:29 +0800 Subject: [PATCH 10/15] [Change]: change FILE_SYSTEM to FILESYSTEM --- examples/IRMQTTServer/IRMQTTServer.h | 12 ++++----- examples/IRMQTTServer/IRMQTTServer.ino | 34 +++++++++++++------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.h b/examples/IRMQTTServer/IRMQTTServer.h index af2fc8e17..b59765f7e 100644 --- a/examples/IRMQTTServer/IRMQTTServer.h +++ b/examples/IRMQTTServer/IRMQTTServer.h @@ -35,16 +35,16 @@ // type of persistent storage is used. // Warning: Changing filesystems will cause all previous locally // saved configuration data to be lost. -// #define FILE_SYSTEM SPIFFS -// #define FILE_SYSTEM LittleFS -#ifndef FILE_SYSTEM +// #define FILESYSTEM SPIFFS +// #define FILESYSTEM LittleFS +#ifndef FILESYSTEM // Set the default filesystem if none was specified. #ifdef ESP8266 -#define FILE_SYSTEM LittleFS +#define FILESYSTEM LittleFS #else -#define FILE_SYSTEM SPIFFS +#define FILESYSTEM SPIFFS #endif // defined(ESP8266) -#endif // FILE_SYSTEM +#endif // FILESYSTEM // ---------------------- Board Related Settings ------------------------------- // NOTE: Make sure you set your Serial Monitor to the same speed. #define BAUD_RATE 115200 // Serial port Baud rate. diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index d01d457ef..f9e4f3c26 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -38,7 +38,7 @@ * o You MUST change to have the following (or larger) value: * (with REPORT_RAW_UNKNOWNS 1024 or more is recommended) * #define MQTT_MAX_PACKET_SIZE 768 - * o Use the smallest non-zero FILE_SYSTEM size you can for your board. + * o Use the smallest non-zero FILESYSTEM size you can for your board. * (See the Tools -> Flash Size menu) * * - PlatformIO IDE: @@ -517,19 +517,19 @@ void saveWifiConfigCallback(void) { flagSaveWifiConfig = true; } -// Forcibly mount the FILE_SYSTEM. Formatting the FILE_SYSTEM if needed. +// Forcibly mount the FILESYSTEM. Formatting the FILESYSTEM if needed. // // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { - debug("Mounting FILE_SYSTEM..."); - if (FILE_SYSTEM.begin()) return true; // We mounted it okay. + debug("Mounting FILESYSTEM..."); + if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. - debug("Failed to mount FILE_SYSTEM!\n" - "Formatting FILE_SYSTEM and trying again..."); - FILE_SYSTEM.format(); - if (!FILE_SYSTEM.begin()) { // Did we fail? - debug("DANGER: Failed to mount FILE_SYSTEM even after formatting!"); + debug("Failed to mount FILESYSTEM!\n" + "Formatting FILESYSTEM and trying again..."); + FILESYSTEM.format(); + if (!FILESYSTEM.begin()) { // Did we fail? + debug("DANGER: Failed to mount FILESYSTEM even after formatting!"); delay(10000); // Make sure the debug message doesn't just float by. return false; } @@ -559,7 +559,7 @@ bool saveConfig(void) { } if (mountSpiffs()) { - File configFile = FILE_SYSTEM.open(kConfigFile, "w"); + File configFile = FILESYSTEM.open(kConfigFile, "w"); if (!configFile) { debug("Failed to open config file for writing."); } else { @@ -569,7 +569,7 @@ bool saveConfig(void) { debug("Finished writing config file."); success = true; } - FILE_SYSTEM.end(); + FILESYSTEM.end(); } return success; } @@ -578,9 +578,9 @@ bool loadConfigFile(void) { bool success = false; if (mountSpiffs()) { debug("mounted the file system"); - if (FILE_SYSTEM.exists(kConfigFile)) { + if (FILESYSTEM.exists(kConfigFile)) { debug("config file exists"); - File configFile = FILE_SYSTEM.open(kConfigFile, "r"); + File configFile = FILESYSTEM.open(kConfigFile, "r"); if (configFile) { debug("Opened config file"); size_t size = configFile.size(); @@ -621,8 +621,8 @@ bool loadConfigFile(void) { } else { debug("Config file doesn't exist!"); } - debug("Unmounting FILE_SYSTEM."); - FILE_SYSTEM.end(); + debug("Unmounting FILESYSTEM."); + FILESYSTEM.end(); } return success; } @@ -1456,8 +1456,8 @@ void handleReset(void) { #endif // MQTT_ENABLE if (mountSpiffs()) { debug("Removing JSON config file"); - FILE_SYSTEM.remove(kConfigFile); - FILE_SYSTEM.end(); + FILESYSTEM.remove(kConfigFile); + FILESYSTEM.end(); } delay(1000); debug("Reseting wifiManager's settings."); From fec76d33f80df1e9192634ce6a5239a5c0acd573 Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Wed, 5 Aug 2020 08:36:16 +0800 Subject: [PATCH 11/15] Add WiFiManager --- examples/Web-AC-control/platformio.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/Web-AC-control/platformio.ini b/examples/Web-AC-control/platformio.ini index 7714b5454..8642c095c 100644 --- a/examples/Web-AC-control/platformio.ini +++ b/examples/Web-AC-control/platformio.ini @@ -32,7 +32,7 @@ platform = espressif8266 board = nodemcuv2 lib_deps = ${common_esp8266.lib_deps_external} board_build.ldscript = ${common.ldscript_4m} -; [env:esp32dev] -; platform = espressif32 -; board = esp32dev -; lib_deps = ${common_esp32.lib_deps_external} +[env:esp32dev] +platform = espressif32 +board = esp32dev +lib_deps = ${common_esp32.lib_deps_external} From 102596edb35920e9f8d3fcfa35d3f429d14b09fc Mon Sep 17 00:00:00 2001 From: ymiao Date: Fri, 7 Aug 2020 10:33:24 +0800 Subject: [PATCH 12/15] Report if it is SPIFFS or LittleFS --- examples/IRMQTTServer/IRMQTTServer.h | 1 + examples/IRMQTTServer/IRMQTTServer.ino | 30 ++++++++++++++++------ examples/Web-AC-control/Web-AC-control.ino | 14 +++++----- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.h b/examples/IRMQTTServer/IRMQTTServer.h index b59765f7e..656763dc9 100644 --- a/examples/IRMQTTServer/IRMQTTServer.h +++ b/examples/IRMQTTServer/IRMQTTServer.h @@ -4,6 +4,7 @@ */ #ifndef EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ #define EXAMPLES_IRMQTTSERVER_IRMQTTSERVER_H_ + #if defined(ESP8266) #include #else diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index f9e4f3c26..b822ce386 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -380,9 +380,6 @@ using irutils::msToString; #endif // REPORT_VCC // Globals - - - #if defined(ESP8266) ESP8266WebServer server(kHttpPort); #endif // ESP8266 @@ -522,14 +519,27 @@ void saveWifiConfigCallback(void) { // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { - debug("Mounting FILESYSTEM..."); +#if (FILESYSTEM == LittleFS) + debug("Mounting LittleFS ..."); +#else + debug("Mounting SPIFFS ..."); +#endif if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. - debug("Failed to mount FILESYSTEM!\n" - "Formatting FILESYSTEM and trying again..."); +#if (FILESYSTEM == LittleFS) + debug("Failed to mount LittleFS!\n" + "Formatting LittleFS and trying again..."); +#else + debug("Failed to mount SPIFFS!\n" + "Formatting SPIFFS and trying again..."); +#endif FILESYSTEM.format(); if (!FILESYSTEM.begin()) { // Did we fail? - debug("DANGER: Failed to mount FILESYSTEM even after formatting!"); +#if (FILESYSTEM == LittleFS) + debug("DANGER: Failed to mount LittleFS even after formatting!"); +#else + debug("DANGER: Failed to mount SPIFFS even after formatting!"); +#endif delay(10000); // Make sure the debug message doesn't just float by. return false; } @@ -621,7 +631,11 @@ bool loadConfigFile(void) { } else { debug("Config file doesn't exist!"); } - debug("Unmounting FILESYSTEM."); +#if (FILESYSTEM == LittleFS) + debug("Unmounting LittleFS."); +#else + debug("Unmounting SPIFFS."); +#endif FILESYSTEM.end(); } return success; diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index c1c2ebd13..134c8ad52 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -72,7 +72,7 @@ WebServer server(80); bool handleFileRead(String path) { // send the right file to the client (if it exists) - Serial.println("handleFileRead: " + path); + // Serial.println("handleFileRead: " + path); if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file String contentType = getContentType(path); @@ -89,10 +89,10 @@ bool handleFileRead(String path) { // Send it to the client file.close(); // Close the file again - Serial.println(String("\tSent file: ") + path); + // Serial.println(String("\tSent file: ") + path); return true; } - Serial.println(String("\tFile Not Found: ") + path); + // Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false return false; } @@ -125,8 +125,8 @@ void handleFileUpload() { // upload a new file to the FILESYSTEM // If the file was successfully created fsUploadFile.close(); // Close the file again - Serial.print("handleFileUpload Size: "); - Serial.println(upload.totalSize); + // Serial.print("handleFileUpload Size: "); + // Serial.println(upload.totalSize); server.sendHeader("Location", "/success.html"); // Redirect the client to the success page server.send(303); @@ -153,8 +153,8 @@ void handleNotFound() { } void setup() { - Serial.begin(115200); - Serial.println(); + // Serial.begin(115200); + // Serial.println(); ac.begin(); From 685450db04ae06dc02cca34d33e0f6d3e504442a Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 11 Aug 2020 19:25:29 +0800 Subject: [PATCH 13/15] Reduces code duplication --- examples/IRMQTTServer/IRMQTTServer.h | 6 +++++ examples/IRMQTTServer/IRMQTTServer.ino | 26 +++++----------------- examples/Web-AC-control/Web-AC-control.h | 6 +++++ examples/Web-AC-control/Web-AC-control.ino | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.h b/examples/IRMQTTServer/IRMQTTServer.h index 656763dc9..86d49dbd2 100644 --- a/examples/IRMQTTServer/IRMQTTServer.h +++ b/examples/IRMQTTServer/IRMQTTServer.h @@ -46,6 +46,12 @@ #define FILESYSTEM SPIFFS #endif // defined(ESP8266) #endif // FILESYSTEM + +#if (FILESYSTEM == LittleFS) +#define FILESYSTEMSTR "LittleFS" +#else +#define FILESYSTEMSTR "SPIFFS" +#endif // ---------------------- Board Related Settings ------------------------------- // NOTE: Make sure you set your Serial Monitor to the same speed. #define BAUD_RATE 115200 // Serial port Baud rate. diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index b822ce386..e1906c850 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -519,27 +519,15 @@ void saveWifiConfigCallback(void) { // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { -#if (FILESYSTEM == LittleFS) - debug("Mounting LittleFS ..."); -#else - debug("Mounting SPIFFS ..."); -#endif + debug("Mounting " FILESYSTEMSTR " ..." ); if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. -#if (FILESYSTEM == LittleFS) - debug("Failed to mount LittleFS!\n" - "Formatting LittleFS and trying again..."); -#else - debug("Failed to mount SPIFFS!\n" + debug("Failed to mount " FILESYSTEMSTR "!\n" "Formatting SPIFFS and trying again..."); -#endif FILESYSTEM.format(); if (!FILESYSTEM.begin()) { // Did we fail? -#if (FILESYSTEM == LittleFS) - debug("DANGER: Failed to mount LittleFS even after formatting!"); -#else - debug("DANGER: Failed to mount SPIFFS even after formatting!"); -#endif + debug("DANGER: Failed to mount " FILESYSTEMSTR "even after formatting!"); + delay(10000); // Make sure the debug message doesn't just float by. return false; } @@ -631,11 +619,7 @@ bool loadConfigFile(void) { } else { debug("Config file doesn't exist!"); } -#if (FILESYSTEM == LittleFS) - debug("Unmounting LittleFS."); -#else - debug("Unmounting SPIFFS."); -#endif + debug("Unmounting " FILESYSTEMSTR); FILESYSTEM.end(); } return success; diff --git a/examples/Web-AC-control/Web-AC-control.h b/examples/Web-AC-control/Web-AC-control.h index 755761df2..3d73ac4a5 100644 --- a/examples/Web-AC-control/Web-AC-control.h +++ b/examples/Web-AC-control/Web-AC-control.h @@ -28,4 +28,10 @@ #define FILESYSTEM SPIFFS #endif // defined(ESP8266) #endif // FILESYSTEM + +#if (FILESYSTEM == LittleFS) +#define FILESYSTEMSTR "LittleFS" +#else +#define FILESYSTEMSTR "SPIFFS" +#endif #endif // EXAMPLES_WEB_AC_CONTROL_WEB_AC_CONTROL_H_ diff --git a/examples/Web-AC-control/Web-AC-control.ino b/examples/Web-AC-control/Web-AC-control.ino index 134c8ad52..707c3f615 100644 --- a/examples/Web-AC-control/Web-AC-control.ino +++ b/examples/Web-AC-control/Web-AC-control.ino @@ -160,7 +160,7 @@ void setup() { delay(1000); - Serial.println("mounting FS..."); + Serial.println("mounting " FILESYSTEMSTR "..."); if (!FILESYSTEM.begin()) { // Serial.println("Failed to mount file system"); From e2f5327cf8fa68344ebd1f49515b1431a15ade3c Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 11 Aug 2020 20:56:19 +0800 Subject: [PATCH 14/15] Fix format error --- examples/IRMQTTServer/IRMQTTServer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index e1906c850..f09c0e47b 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -526,7 +526,7 @@ bool mountSpiffs(void) { "Formatting SPIFFS and trying again..."); FILESYSTEM.format(); if (!FILESYSTEM.begin()) { // Did we fail? - debug("DANGER: Failed to mount " FILESYSTEMSTR "even after formatting!"); + debug("DANGER: Failed to mount " FILESYSTEMSTR " even after formatting!"); delay(10000); // Make sure the debug message doesn't just float by. return false; From 178ae10291781d17f72eb5c9bb0e0c63f4cf40ac Mon Sep 17 00:00:00 2001 From: Caffreyfans Date: Tue, 11 Aug 2020 21:13:34 +0800 Subject: [PATCH 15/15] Fix format error --- examples/IRMQTTServer/IRMQTTServer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index f09c0e47b..7d97a5ae3 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -519,7 +519,7 @@ void saveWifiConfigCallback(void) { // Returns: // A boolean indicating success or failure. bool mountSpiffs(void) { - debug("Mounting " FILESYSTEMSTR " ..." ); + debug("Mounting " FILESYSTEMSTR " ..."); if (FILESYSTEM.begin()) return true; // We mounted it okay. // We failed the first time. debug("Failed to mount " FILESYSTEMSTR "!\n"