mirror of
https://github.com/schinken/esp8266-geigercounter.git
synced 2024-11-14 04:54:21 +01:00
37 lines
912 B
C++
37 lines
912 B
C++
void saveConfig() {
|
|
DynamicJsonDocument json(512);
|
|
json["mqtt_server"] = mqtt_server;
|
|
json["username"] = username;
|
|
json["password"] = password;
|
|
|
|
File configFile = SPIFFS.open("/config.json", "w");
|
|
if (!configFile) {
|
|
return;
|
|
}
|
|
|
|
serializeJson(json, configFile);
|
|
configFile.close();
|
|
}
|
|
|
|
void loadConfig() {
|
|
if (SPIFFS.begin()) {
|
|
|
|
if (SPIFFS.exists("/config.json")) {
|
|
File configFile = SPIFFS.open("/config.json", "r");
|
|
|
|
if (configFile) {
|
|
const size_t size = configFile.size();
|
|
std::unique_ptr<char[]> buf(new char[size]);
|
|
|
|
configFile.readBytes(buf.get(), size);
|
|
DynamicJsonDocument json(512);
|
|
|
|
if (DeserializationError::Ok == deserializeJson(json, buf.get())) {
|
|
strcpy(mqtt_server, json["mqtt_server"]);
|
|
strcpy(username, json["username"]);
|
|
strcpy(password, json["password"]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|