change path, correct UART output.

This commit is contained in:
elmo128 2023-09-13 03:06:54 +02:00
parent 3ea676ec76
commit 281f5ec702
2 changed files with 24 additions and 24 deletions

View File

@ -8,8 +8,8 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "..\drivers.h" #include "..\drivers.h"
#include "..\storage.h" #include "storage.h"
#include "..\SPIStorage\SPIStorage.h" #include "SPIStorage.h"
#define JSON_CONFIG_FILE "/config.json" #define JSON_CONFIG_FILE "/config.json"
@ -43,13 +43,13 @@ public:
if (SD_MMC.cardType() == CARD_NONE) if (SD_MMC.cardType() == CARD_NONE)
SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
#else #else
Serial.println("SD card interface not available."); Serial.println("SDCard: interface not available.");
return false; return false;
#endif // dataPinsDefined #endif // dataPinsDefined
if ((!SD_MMC.begin("/sdcard", oneBitMode)) || (SD_MMC.cardType() == CARD_NONE)) if ((!SD_MMC.begin("/sdcard", oneBitMode)) || (SD_MMC.cardType() == CARD_NONE))
{ {
Serial.println("No card available."); Serial.println("SDCard: No card found.");
return false; return false;
} }
return true; return true;
@ -59,27 +59,27 @@ public:
{ {
// Load existing configuration file // Load existing configuration file
// Read configuration from FS json // Read configuration from FS json
Serial.println("Mounting SD card..."); Serial.println("SDCard: Mounting File System...");
TSettings Settings; TSettings Settings;
if (initSDcard()) if (initSDcard())
{ {
Serial.println("mounted SD card."); Serial.println("SDCard: Mounted");
if (SD_MMC.exists(JSON_CONFIG_FILE)) if (SD_MMC.exists(JSON_CONFIG_FILE))
{ {
// The file exists, reading and loading // The file exists, reading and loading
Serial.println("reading config file from sd."); Serial.println("SDCard: Reading config file");
File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r");
if (configFile) if (configFile)
{ {
Serial.println("Opened configuration file"); Serial.println("SDCard: Opened configuration file");
StaticJsonDocument<512> json; StaticJsonDocument<512> json;
DeserializationError error = deserializeJson(json, configFile); DeserializationError error = deserializeJson(json, configFile);
configFile.close(); configFile.close();
serializeJsonPretty(json, Serial); serializeJsonPretty(json, Serial);
if (!error) if (!error)
{ {
Serial.println("Parsing JSON"); Serial.println("SDCard: Parsing JSON");
strcpy(Settings.WifiSSID, json["SSID"]); strcpy(Settings.WifiSSID, json["SSID"]);
strcpy(Settings.WifiPW, json["Password"]); strcpy(Settings.WifiPW, json["Password"]);
strcpy(Settings.PoolAddress, json["PoolURL"]); strcpy(Settings.PoolAddress, json["PoolURL"]);
@ -91,7 +91,7 @@ public:
else else
{ {
// Error loading JSON data // Error loading JSON data
Serial.println("Failed to load json config"); Serial.println("SDCard: Failed to load json config");
} }
} }
SD_MMC.end(); SD_MMC.end();
@ -100,7 +100,7 @@ public:
else else
{ {
// Error mounting file system // Error mounting file system
Serial.println("Failed to mount SD card."); Serial.println("SDCard: Failed to mount.");
} }
return Settings; return Settings;
} }
@ -112,7 +112,7 @@ public:
{ {
spifs->saveConfigFile(&Settings); spifs->saveConfigFile(&Settings);
WiFi.begin(Settings.WifiSSID, Settings.WifiPW); WiFi.begin(Settings.WifiSSID, Settings.WifiPW);
Serial.println("Settings copied from SD card. Rebooting now."); Serial.println("SDCard: Settings transfered to internal memory. Restarting now.");
ESP.restart(); ESP.restart();
} }
} }

View File

@ -10,7 +10,7 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "..\drivers.h" #include "..\drivers.h"
#include "..\storage.h" #include "storage.h"
// JSON configuration file // JSON configuration file
#define JSON_CONFIG_FILE "/config.json" #define JSON_CONFIG_FILE "/config.json"
@ -33,7 +33,7 @@ public:
void saveConfigFile(TSettings*Settings) void saveConfigFile(TSettings*Settings)
{ {
// Save Config in JSON format // Save Config in JSON format
Serial.println(F("Saving configuration...")); Serial.println(F("SPIFS: Saving configuration..."));
// Create a JSON document // Create a JSON document
StaticJsonDocument<512> json; StaticJsonDocument<512> json;
@ -47,7 +47,7 @@ public:
if (!configFile) if (!configFile)
{ {
// Error, file did not open // Error, file did not open
Serial.println("failed to open config file for writing"); Serial.println("SPIFS: failed to open config file for writing");
} }
// Serialize JSON data to write to file // Serialize JSON data to write to file
@ -55,7 +55,7 @@ public:
if (serializeJson(json, configFile) == 0) if (serializeJson(json, configFile) == 0)
{ {
// Error writing file // Error writing file
Serial.println(F("Failed to write to file")); Serial.println(F("SPIFS: Failed to write to file"));
} }
// Close file // Close file
configFile.close(); configFile.close();
@ -75,27 +75,27 @@ public:
// SPIFFS.format(); // SPIFFS.format();
// Read configuration from FS json // Read configuration from FS json
Serial.println("Mounting File System..."); Serial.println("SPIFS: Mounting File System...");
TSettings Settings; TSettings Settings;
// May need to make it begin(true) first time you are using SPIFFS // May need to make it begin(true) first time you are using SPIFFS
if ((SPIFFSInitialized_)||(init())) if ((SPIFFSInitialized_)||(init()))
{ {
Serial.println("mounted file system"); Serial.println("SPIFS: Mounted");
if (SPIFFS.exists(JSON_CONFIG_FILE)) if (SPIFFS.exists(JSON_CONFIG_FILE))
{ {
// The file exists, reading and loading // The file exists, reading and loading
Serial.println("reading config file"); Serial.println("SPIFS: Reading config file");
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r"); File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r");
if (configFile) if (configFile)
{ {
Serial.println("Opened configuration file"); Serial.println("SPIFS: Opened configuration file");
StaticJsonDocument<512> json; StaticJsonDocument<512> json;
DeserializationError error = deserializeJson(json, configFile); DeserializationError error = deserializeJson(json, configFile);
configFile.close(); configFile.close();
serializeJsonPretty(json, Serial); serializeJsonPretty(json, Serial);
if (!error) if (!error)
{ {
Serial.println("Parsing JSON"); Serial.println("SPIFS: Parsing JSON");
strcpy(Settings.PoolAddress, json["poolString"]); strcpy(Settings.PoolAddress, json["poolString"]);
strcpy(Settings.BtcWallet, json["btcString"]); strcpy(Settings.BtcWallet, json["btcString"]);
@ -106,7 +106,7 @@ public:
else else
{ {
// Error loading JSON data // Error loading JSON data
Serial.println("Failed to load json config"); Serial.println("SPIFS: Failed to load json config");
} }
} }
} }
@ -114,14 +114,14 @@ public:
else else
{ {
// Error mounting file system // Error mounting file system
Serial.println("Failed to mount FS"); Serial.println("SPIFS: Failed to mount.");
} }
return Settings; return Settings;
} }
void deleteConfigFile() void deleteConfigFile()
{ {
Serial.println("Erasing config file.."); Serial.println("SPIFS: Erasing config file..");
SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero
} }
}; };