diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index e5a9578..6ef8c45 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -32,6 +32,8 @@ * Libraries include */ +#include "Arduino.h" + // * ESP8266 * #ifdef ESP8266 #include @@ -40,17 +42,19 @@ // * ESP32 * #ifdef ESP32 -#include "Arduino.h" + #include #include "AsyncTCP.h" #endif +// https://github.com/mathieucarbou/ESPAsyncWebServer +#include + // https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI #include // https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire #include -// https://github.com/lacamera/ESPAsyncWebServer -#include + // https://github.com/bblanchon/ArduinoJson #include // https://github.com/PaulStoffregen/Time @@ -79,6 +83,7 @@ #include "include/CanGrow.h" #include "include/CanGrow_Core.h" #include "include/CanGrow_LittleFS.h" +#include "include/CanGrow_Webserver.h" void setup() { @@ -124,7 +129,7 @@ void setup() { LFS_init(); - loadConfig(); + LoadConfig(); if(strlen(configWifi.ssid) == 0) { Serial.println(":: [SETUP] configWifi.ssid is empty, creating access point"); @@ -141,7 +146,7 @@ bool alrdySaved = false; void loop() { if((digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == false)) { Serial.println(":: [LOOP] PinWIPE is triggered, saving config.json"); - saveConfig(); + SaveConfig(); alrdySaved = true; } else if( (digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == true) ) { alrdySaved = true; diff --git a/Arduino/CanGrow/cangrow.sh b/Arduino/CanGrow/cangrow.sh index 78f8313..89f0ae9 100755 --- a/Arduino/CanGrow/cangrow.sh +++ b/Arduino/CanGrow/cangrow.sh @@ -46,8 +46,8 @@ case $1 in "NTPClient@3.2.1" "Time@1.6.1" "ESP Async WebServer@3.3.17" + "Async TCP@3.2.10" "ESPAsyncTCP@1.2.4" - "AsyncTCP@1.1.4" ) echo ":: Setting up build environment for CanGrow Firmware." echo " This will download the binary for arduino-cli and install" diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index 12348e3..f696401 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -60,6 +60,8 @@ struct Config_System { byte ntpOffset; unsigned short maintenanceDuration; char esp32camIp[16]; + char httpUser[32]; + char httpPass[32]; }; Config_System configSystem; diff --git a/Arduino/CanGrow/include/CanGrow_Core.h b/Arduino/CanGrow/include/CanGrow_Core.h index 24d65a6..01ddfc7 100644 --- a/Arduino/CanGrow/include/CanGrow_Core.h +++ b/Arduino/CanGrow/include/CanGrow_Core.h @@ -27,6 +27,7 @@ * */ + // blink fast with the built in LED in an infinite loop void Panic() { Serial.println("!! PANIC !!"); diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h index 7075a0d..5d2f969 100644 --- a/Arduino/CanGrow/include/CanGrow_LittleFS.h +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -149,7 +149,7 @@ void deleteFile(const char *path) { // https://arduinojson.org/v7/example/config/ // https://arduinojson.org/v7/assistant/ -bool loadConfig() { +bool LoadConfig() { #ifdef ESP8266 File file = LittleFS.open(CANGROW_CFG, "r"); #endif @@ -159,13 +159,13 @@ bool loadConfig() { File file = fs.open(CANGROW_CFG); #endif - Serial.printf(":: [LittleFS] loading config from: %s\n", CANGROW_CFG); + Serial.printf(":: [LittleFS:LoadConfig] loading config from: %s\n", CANGROW_CFG); JsonDocument doc; // Deserialize the JSON document DeserializationError error = deserializeJson(doc, file); if(error) { - Serial.printf(":: [LittleFS] FAILED to load config: %s\n", CANGROW_CFG); + Serial.printf(":: [LittleFS:LoadConfig] FAILED to load config: %s\n", CANGROW_CFG); if (existFile(CANGROW_CFG)) { readFile(CANGROW_CFG); } @@ -200,6 +200,8 @@ bool loadConfig() { configSystem.ntpOffset = objSystem["ntpOffset"]; configSystem.maintenanceDuration = objSystem["maintenanceDuration"]; strlcpy(configSystem.esp32camIp, objSystem["esp32camIp"], sizeof(configSystem.esp32camIp)); + strlcpy(configSystem.httpUser, objSystem["httpUser"], sizeof(configSystem.httpUser)); + strlcpy(configSystem.httpPass, objSystem["httpPass"], sizeof(configSystem.httpPass)); // * Grow * JsonObject objGrow = doc["grow"][0]; @@ -219,11 +221,11 @@ bool loadConfig() { // Close the file (Curiously, File's destructor doesn't close the file) file.close(); - Serial.println(":: [LittleFS] config successfully loaded"); + Serial.println(":: [LittleFS:LoadConfig] config successfully loaded"); return true; } -void saveConfig() { +void SaveConfig(bool writeToSerial = false) { #ifdef ESP8266 File file = LittleFS.open(CANGROW_CFG, "w"); #endif @@ -234,10 +236,10 @@ void saveConfig() { #endif if (!file) { - Serial.printf("!! [LittleFS] FAILED to open configfile for writing: %s\n", CANGROW_CFG); + Serial.printf("!! [LittleFS:SaveConfig] FAILED to open configfile for writing: %s\n", CANGROW_CFG); return; } else { - Serial.printf(":: [LittleFS] opened for writing %s\n", CANGROW_CFG); + Serial.printf(":: [LittleFS:SaveConfig] opened for writing %s\n", CANGROW_CFG); } /* @@ -267,6 +269,8 @@ void saveConfig() { objSystem["ntpOffset"] = configSystem.ntpOffset; objSystem["maintenanceDuration"] = configSystem.maintenanceDuration; objSystem["esp32camIp"] = configSystem.esp32camIp; + objSystem["httpUser"] = configSystem.httpUser; + objSystem["httpPass"] = configSystem.httpPass; // * Grow * JsonObject objGrow = doc["grow"].add(); @@ -286,15 +290,21 @@ void saveConfig() { * END Building config.json here */ - // Serialize JSON to file if (serializeJson(doc, file) == 0) { - Serial.printf("!! [LittleFS] FAILED to write configfile: %s\n", CANGROW_CFG); + Serial.printf("!! [LittleFS:SaveConfig] FAILED to write configfile: %s\n", CANGROW_CFG); } else { - Serial.printf(":: [LittleFS] successfully written %s\n", CANGROW_CFG); + Serial.printf(":: [LittleFS:SaveConfig] successfully written %s\n", CANGROW_CFG); + } + file.close(); + + if(writeToSerial == true) { + Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG); + serializeJson(doc, Serial); + Serial.println(""); + Serial.printf(":: [LittleFS:SaveConfig] --- %s ---\n", CANGROW_CFG); } - file.close(); } ///*