minor small changes
This commit is contained in:
parent
6ac7b31602
commit
8e9a07a65b
5 changed files with 35 additions and 17 deletions
|
@ -32,6 +32,8 @@
|
|||
* Libraries include
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
// * ESP8266 *
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
|
@ -40,17 +42,19 @@
|
|||
|
||||
// * ESP32 *
|
||||
#ifdef ESP32
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include "AsyncTCP.h"
|
||||
#endif
|
||||
|
||||
// https://github.com/mathieucarbou/ESPAsyncWebServer
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI
|
||||
#include <SPI.h>
|
||||
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire
|
||||
#include <Wire.h>
|
||||
// https://github.com/lacamera/ESPAsyncWebServer
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
#include <ArduinoJson.h>
|
||||
// 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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -60,6 +60,8 @@ struct Config_System {
|
|||
byte ntpOffset;
|
||||
unsigned short maintenanceDuration;
|
||||
char esp32camIp[16];
|
||||
char httpUser[32];
|
||||
char httpPass[32];
|
||||
};
|
||||
|
||||
Config_System configSystem;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
// blink fast with the built in LED in an infinite loop
|
||||
void Panic() {
|
||||
Serial.println("!! PANIC !!");
|
||||
|
|
|
@ -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<JsonObject>();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
///*
|
||||
|
|
Loading…
Reference in a new issue