mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Add Web config page
This commit is contained in:
parent
3bc0ee7180
commit
8915eb0b23
@ -18,7 +18,8 @@
|
|||||||
#include "hasp_ota.h"
|
#include "hasp_ota.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
|
||||||
#define HASP_CONFIG_FILE F("/config.json")
|
//#define HASP_CONFIG_FILE F("/config.json")
|
||||||
|
static const char HASP_CONFIG_FILE[] PROGMEM = "/config.json";
|
||||||
|
|
||||||
void spiffsList()
|
void spiffsList()
|
||||||
{
|
{
|
||||||
@ -58,7 +59,7 @@ void configLoop()
|
|||||||
|
|
||||||
void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
||||||
{
|
{
|
||||||
File file = SPIFFS.open(HASP_CONFIG_FILE, "r");
|
File file = SPIFFS.open(FPSTR(HASP_CONFIG_FILE), "r");
|
||||||
|
|
||||||
if(file) {
|
if(file) {
|
||||||
size_t size = file.size();
|
size_t size = file.size();
|
||||||
@ -76,14 +77,14 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
debugPrintln(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
debugPrintln(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
||||||
spiffsList();
|
spiffsList();
|
||||||
}
|
}
|
||||||
debugPrintln(String(F("CONF: Loading ")) + String(HASP_CONFIG_FILE));
|
debugPrintln(String(F("CONF: Loading ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
|
|
||||||
// show settings in log
|
// show settings in log
|
||||||
String output;
|
String output;
|
||||||
serializeJson(settings, output);
|
serializeJson(settings, output);
|
||||||
debugPrintln(String(F("CONF: ")) + output);
|
debugPrintln(String(F("CONF: ")) + output);
|
||||||
|
|
||||||
debugPrintln(String(F("CONF: [SUCCESS] Loaded ")) + String(HASP_CONFIG_FILE));
|
debugPrintln(String(F("CONF: [SUCCESS] Loaded ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,23 +95,23 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
|
|||||||
debugPrintln(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
debugPrintln(F("FILE: [SUCCESS] SPI flash FS mounted"));
|
||||||
spiffsList();
|
spiffsList();
|
||||||
}
|
}
|
||||||
debugPrintln(String(F("CONF: Loading ")) + String(HASP_CONFIG_FILE));
|
debugPrintln(String(F("CONF: Loading ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
errorPrintln(String(F("CONF: %sFailed to load ")) + String(HASP_CONFIG_FILE));
|
errorPrintln(String(F("CONF: %sFailed to load ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void configWriteConfig()
|
void configWriteConfig()
|
||||||
{
|
{
|
||||||
/* Read Config File */
|
/* Read Config File */
|
||||||
DynamicJsonDocument settings(1024);
|
DynamicJsonDocument settings(1024);
|
||||||
debugPrintln(String(F("CONF: Config LOADING first")) + String(HASP_CONFIG_FILE));
|
debugPrintln(String(F("CONF: Config LOADING first ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
configGetConfig(settings, false);
|
configGetConfig(settings, false);
|
||||||
debugPrintln(String(F("CONF: Config LOADED first")) + String(HASP_CONFIG_FILE));
|
debugPrintln(String(F("CONF: Config LOADED first ")) + String(FPSTR(HASP_CONFIG_FILE)));
|
||||||
|
|
||||||
bool changed = true;
|
bool changed = true;
|
||||||
// changed |= debugGetConfig(settings[F("debug")].to<JsonObject>());
|
// changed |= debugGetConfig(settings[F("debug")].to<JsonObject>());
|
||||||
// changed |= guiGetConfig(settings[F("gui")].to<JsonObject>());
|
// changed |= guiGetConfig(settings[F("gui")].to<JsonObject>());
|
||||||
changed |= haspGetConfig(settings[F("hasp")].to<JsonObject>());
|
changed |= haspGetConfig(settings[F("hasp")].to<JsonObject>());
|
||||||
// changed |= httpGetConfig(settings[F("http")].to<JsonObject>());
|
changed |= httpGetConfig(settings[F("http")].to<JsonObject>());
|
||||||
// changed |= mdnsGetConfig(settings[F("mdns")].to<JsonObject>());
|
// changed |= mdnsGetConfig(settings[F("mdns")].to<JsonObject>());
|
||||||
changed |= mqttGetConfig(settings[F("mqtt")].to<JsonObject>());
|
changed |= mqttGetConfig(settings[F("mqtt")].to<JsonObject>());
|
||||||
// changed |= otaGetConfig(settings[F("ota")].to<JsonObject>());
|
// changed |= otaGetConfig(settings[F("ota")].to<JsonObject>());
|
||||||
@ -118,7 +119,7 @@ void configWriteConfig()
|
|||||||
changed |= wifiGetConfig(settings[F("wifi")].to<JsonObject>());
|
changed |= wifiGetConfig(settings[F("wifi")].to<JsonObject>());
|
||||||
|
|
||||||
if(changed) {
|
if(changed) {
|
||||||
File file = SPIFFS.open(HASP_CONFIG_FILE, "w");
|
File file = SPIFFS.open(FPSTR(HASP_CONFIG_FILE), "w");
|
||||||
if(file) {
|
if(file) {
|
||||||
debugPrintln(F("CONF: Writing /config.json"));
|
debugPrintln(F("CONF: Writing /config.json"));
|
||||||
size_t size = serializeJson(settings, file);
|
size_t size = serializeJson(settings, file);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user