-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
74 lines (66 loc) · 1.33 KB
/
config.cpp
File metadata and controls
74 lines (66 loc) · 1.33 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <FS.h>
#include <ArduinoJson.h>
#include "config.h"
#include "util.h"
String initialConfig = R"(
{
"color": {
"mode": 0,
"fade_delay": 50,
"step_delay": 500,
"is_gradient": false,
"colors": [
"0xFF0000",
"0xFFFFFF",
"0x0000FF"
]
},
"lights": {
"count": 20,
"start_time": 0,
"end_time": 0,
"is_enabled": true,
"brightness": 255
},
"wifi": {
"mode": 1,
"ssid": "",
"password": "",
"pk": ""
},
"data_pin": 1,
"mdns_name": "",
"friendly_name": "",
"ip_address": "0.0.0.0",
"mac_address": ""
}
)";
bool isConfigured;
StaticJsonDocument<2048> config;
void initConfig() {
File configFile = SPIFFS.open(CONFIG_FILE, "r");
String cf = configFile.readString();
configFile.close();
String c = (cf != "") ? cf : initialConfig;
log("c string:::" + c);
DeserializationError e = deserializeJson(config, c);
if(e) {
log("Deserialization error: " + String(e.f_str()));
deserializeJson(config, initialConfig);
}
/*else {
log("Initial config: " + initialConfig + " ... ");
deserializeJson(config, initialConfig);
serializeJson(config, configFile);
}*/
}
void checkIsConfigured() {
if (!isConfigured) {
initConfig();
}
}
void saveConfig() {
File configFile = SPIFFS.open(CONFIG_FILE, "w");
serializeJson(config, configFile);
configFile.close();
}