This commit is contained in:
2025-12-12 08:35:20 +01:00
committed by example
parent 356d7de2cf
commit 0ce45a133b
23 changed files with 616 additions and 135 deletions

View File

@@ -11,10 +11,11 @@ CSettings::CSettings()
strcpy(m_aPSK, "");
m_DHCP = true;
strcpy(m_aHostname, "safeweb");
m_Address = IPAddress(0, 0, 0, 0);
m_Netmask = IPAddress(0, 0, 0, 0);
m_Gateway = IPAddress(0, 0, 0, 0);
m_Address = IpAddress(0, 0, 0, 0);
m_Netmask = IpAddress(0, 0, 0, 0);
m_Gateway = IpAddress(0, 0, 0, 0);
memset(m_aLockCode, 0, sizeof(m_aLockCode));
m_SecurityLevel = 4;
}
bool CSettings::Exists()
@@ -53,6 +54,11 @@ bool CSettings::Load()
m_Netmask = network["netmask"].as<const char *>();
m_Gateway = network["gateway"].as<const char *>();
JsonObject mqtt = doc["mqtt"];
strncpy(m_aMqttName, mqtt["client_name"], sizeof(m_aMqttName));
m_MqttURL = Url("mqtt", mqtt["username"], mqtt["password"], mqtt["host"], mqtt["port"]);
m_MqttUnlock = bool(mqtt["unlock"]);
JsonArray lockCode = doc["lock_code"];
uint8_t tmp = min(lockCode.size(), sizeof(m_aLockCode));
for(uint8_t i = 0; i < tmp; i++)
@@ -73,6 +79,8 @@ bool CSettings::Load()
m_FingerPrints[finger.m_FingerNum] = finger;
}
m_SecurityLevel = min(max(int(doc["security_level"]), 1), 5);
delete[] pData;
return true;
}
@@ -93,6 +101,14 @@ void CSettings::Save()
network["netmask"] = m_Netmask.toString();
network["gateway"] = m_Gateway.toString();
JsonObject mqtt = doc.createNestedObject("mqtt");
mqtt["client_name"] = m_aMqttName;
mqtt["host"] = m_MqttURL.Host;
mqtt["port"] = m_MqttURL.getPort();
mqtt["username"] = m_MqttURL.User;
mqtt["password"] = m_MqttURL.Password;
mqtt["unlock"] = m_MqttUnlock;
JsonArray lockCode = doc.createNestedArray("lock_code");
for(uint8_t i = 0; i < sizeof(m_aLockCode); i++)
lockCode.add(m_aLockCode[i]);
@@ -112,6 +128,8 @@ void CSettings::Save()
obj["digest"] = String(aHexDigest);
}
doc["security_level"] = m_SecurityLevel;
String docString;
serializeJsonPretty(doc, docString);
fileSetContent(APP_SETTINGS_FILE, docString);