minor small changes

This commit is contained in:
Marcus 2024-10-19 22:52:19 +02:00
parent 6ac7b31602
commit 8e9a07a65b
5 changed files with 35 additions and 17 deletions

View file

@ -32,6 +32,8 @@
* Libraries include * Libraries include
*/ */
#include "Arduino.h"
// * ESP8266 * // * ESP8266 *
#ifdef ESP8266 #ifdef ESP8266
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
@ -40,17 +42,19 @@
// * ESP32 * // * ESP32 *
#ifdef ESP32 #ifdef ESP32
#include "Arduino.h"
#include <WiFi.h> #include <WiFi.h>
#include "AsyncTCP.h" #include "AsyncTCP.h"
#endif #endif
// https://github.com/mathieucarbou/ESPAsyncWebServer
#include <ESPAsyncWebServer.h>
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI // https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI
#include <SPI.h> #include <SPI.h>
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire // https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire
#include <Wire.h> #include <Wire.h>
// https://github.com/lacamera/ESPAsyncWebServer
#include <ESPAsyncWebServer.h>
// https://github.com/bblanchon/ArduinoJson // https://github.com/bblanchon/ArduinoJson
#include <ArduinoJson.h> #include <ArduinoJson.h>
// https://github.com/PaulStoffregen/Time // https://github.com/PaulStoffregen/Time
@ -79,6 +83,7 @@
#include "include/CanGrow.h" #include "include/CanGrow.h"
#include "include/CanGrow_Core.h" #include "include/CanGrow_Core.h"
#include "include/CanGrow_LittleFS.h" #include "include/CanGrow_LittleFS.h"
#include "include/CanGrow_Webserver.h"
void setup() { void setup() {
@ -124,7 +129,7 @@ void setup() {
LFS_init(); LFS_init();
loadConfig(); LoadConfig();
if(strlen(configWifi.ssid) == 0) { if(strlen(configWifi.ssid) == 0) {
Serial.println(":: [SETUP] configWifi.ssid is empty, creating access point"); Serial.println(":: [SETUP] configWifi.ssid is empty, creating access point");
@ -141,7 +146,7 @@ bool alrdySaved = false;
void loop() { void loop() {
if((digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == false)) { if((digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == false)) {
Serial.println(":: [LOOP] PinWIPE is triggered, saving config.json"); Serial.println(":: [LOOP] PinWIPE is triggered, saving config.json");
saveConfig(); SaveConfig();
alrdySaved = true; alrdySaved = true;
} else if( (digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == true) ) { } else if( (digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == true) ) {
alrdySaved = true; alrdySaved = true;

View file

@ -46,8 +46,8 @@ case $1 in
"NTPClient@3.2.1" "NTPClient@3.2.1"
"Time@1.6.1" "Time@1.6.1"
"ESP Async WebServer@3.3.17" "ESP Async WebServer@3.3.17"
"Async TCP@3.2.10"
"ESPAsyncTCP@1.2.4" "ESPAsyncTCP@1.2.4"
"AsyncTCP@1.1.4"
) )
echo ":: Setting up build environment for CanGrow Firmware." echo ":: Setting up build environment for CanGrow Firmware."
echo " This will download the binary for arduino-cli and install" echo " This will download the binary for arduino-cli and install"

View file

@ -60,6 +60,8 @@ struct Config_System {
byte ntpOffset; byte ntpOffset;
unsigned short maintenanceDuration; unsigned short maintenanceDuration;
char esp32camIp[16]; char esp32camIp[16];
char httpUser[32];
char httpPass[32];
}; };
Config_System configSystem; Config_System configSystem;

View file

@ -27,6 +27,7 @@
* *
*/ */
// blink fast with the built in LED in an infinite loop // blink fast with the built in LED in an infinite loop
void Panic() { void Panic() {
Serial.println("!! PANIC !!"); Serial.println("!! PANIC !!");

View file

@ -149,7 +149,7 @@ void deleteFile(const char *path) {
// https://arduinojson.org/v7/example/config/ // https://arduinojson.org/v7/example/config/
// https://arduinojson.org/v7/assistant/ // https://arduinojson.org/v7/assistant/
bool loadConfig() { bool LoadConfig() {
#ifdef ESP8266 #ifdef ESP8266
File file = LittleFS.open(CANGROW_CFG, "r"); File file = LittleFS.open(CANGROW_CFG, "r");
#endif #endif
@ -159,13 +159,13 @@ bool loadConfig() {
File file = fs.open(CANGROW_CFG); File file = fs.open(CANGROW_CFG);
#endif #endif
Serial.printf(":: [LittleFS] loading config from: %s\n", CANGROW_CFG); Serial.printf(":: [LittleFS:LoadConfig] loading config from: %s\n", CANGROW_CFG);
JsonDocument doc; JsonDocument doc;
// Deserialize the JSON document // Deserialize the JSON document
DeserializationError error = deserializeJson(doc, file); DeserializationError error = deserializeJson(doc, file);
if(error) { 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)) { if (existFile(CANGROW_CFG)) {
readFile(CANGROW_CFG); readFile(CANGROW_CFG);
} }
@ -200,6 +200,8 @@ bool loadConfig() {
configSystem.ntpOffset = objSystem["ntpOffset"]; configSystem.ntpOffset = objSystem["ntpOffset"];
configSystem.maintenanceDuration = objSystem["maintenanceDuration"]; configSystem.maintenanceDuration = objSystem["maintenanceDuration"];
strlcpy(configSystem.esp32camIp, objSystem["esp32camIp"], sizeof(configSystem.esp32camIp)); 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 * // * Grow *
JsonObject objGrow = doc["grow"][0]; JsonObject objGrow = doc["grow"][0];
@ -219,11 +221,11 @@ bool loadConfig() {
// Close the file (Curiously, File's destructor doesn't close the file) // Close the file (Curiously, File's destructor doesn't close the file)
file.close(); file.close();
Serial.println(":: [LittleFS] config successfully loaded"); Serial.println(":: [LittleFS:LoadConfig] config successfully loaded");
return true; return true;
} }
void saveConfig() { void SaveConfig(bool writeToSerial = false) {
#ifdef ESP8266 #ifdef ESP8266
File file = LittleFS.open(CANGROW_CFG, "w"); File file = LittleFS.open(CANGROW_CFG, "w");
#endif #endif
@ -234,10 +236,10 @@ void saveConfig() {
#endif #endif
if (!file) { 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; return;
} else { } 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["ntpOffset"] = configSystem.ntpOffset;
objSystem["maintenanceDuration"] = configSystem.maintenanceDuration; objSystem["maintenanceDuration"] = configSystem.maintenanceDuration;
objSystem["esp32camIp"] = configSystem.esp32camIp; objSystem["esp32camIp"] = configSystem.esp32camIp;
objSystem["httpUser"] = configSystem.httpUser;
objSystem["httpPass"] = configSystem.httpPass;
// * Grow * // * Grow *
JsonObject objGrow = doc["grow"].add<JsonObject>(); JsonObject objGrow = doc["grow"].add<JsonObject>();
@ -286,15 +290,21 @@ void saveConfig() {
* END Building config.json here * END Building config.json here
*/ */
// Serialize JSON to file // Serialize JSON to file
if (serializeJson(doc, file) == 0) { 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 { } 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();
} }
///* ///*