-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconf.cpp
More file actions
38 lines (30 loc) · 773 Bytes
/
Copy pathconf.cpp
File metadata and controls
38 lines (30 loc) · 773 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
34
35
36
37
38
#include "conf.h"
#include <Arduino_JSON.h>
#include <FS.h>
#include <LittleFS.h>
JSONVar conf;
bool loadConfig() {
File configFile = LittleFS.open("/config.json", "r");
if (!configFile) {
// Serial.println("Failed to open config file");
return false;
}
conf = JSON.parse(configFile.readString());
if (JSON.typeof(conf) == "undefined") {
// Serial.println("Failed to parse config file");
return false;
}
configFile.close();
return true;
}
bool saveConfig() {
File configFile = LittleFS.open("/config.json", "w");
if (!configFile) {
// Serial.println("Failed to open config file for writing");
return false;
}
String jsonStr = JSON.stringify(conf);
configFile.println(jsonStr);
configFile.close();
return true;
}