-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cpp
More file actions
33 lines (31 loc) · 900 Bytes
/
Config.cpp
File metadata and controls
33 lines (31 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* WaterTank project
* Copyright (c) 2026 Fedir Vilhota <fredy31415@gmail.com>
* This software is released under the MIT License.
* See the LICENSE file in the project root for full license information.
*/
#include "Config.h"
bool Config::load(const char* filename) {
File configFile = LittleFS.open(filename, "r");
if (!configFile) {
return false;
}
StaticJsonDocument<512> doc;
DeserializationError error = deserializeJson(doc, configFile);
configFile.close();
if (error) {
return false;
}
return true;
}
bool Config::save(const char* filename) {
StaticJsonDocument<512> doc;
File configFile = LittleFS.open(filename, "w");
if (!configFile) {
Serial.println(F("Failed to open config.json for writing"));
return false;
}
serializeJsonPretty(doc, configFile);
configFile.close();
return true;
}