-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJsonConfig.h
More file actions
43 lines (33 loc) · 792 Bytes
/
JsonConfig.h
File metadata and controls
43 lines (33 loc) · 792 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
39
40
41
42
43
#ifndef PM25_NODEMCU_JSONCONFIG_H
#define PM25_NODEMCU_JSONCONFIG_H
class JsonConfig
{
public:
JsonConfig();
String readConfigFile(String file);
private:
virtual void parseConfig(String conf);
};
JsonConfig::JsonConfig() { }
String JsonConfig::readConfigFile(String file) {
SPIFFS.begin();
if (!SPIFFS.exists(file)) {
DEBUG_SERIAL("JsonConfig: No such config file '" + file + "', aborting.");
SPIFFS.end();
return "";
}
File fd = SPIFFS.open(file, "r");
if (!fd) {
DEBUG_SERIAL("JsonConfig: Unable to read-open: '" + file + "'");
SPIFFS.end();
return "";
}
String conf = "";
while(fd.available()) {
conf += fd.readStringUntil('\n');
}
fd.close();
SPIFFS.end();
return conf;
}
#endif // PM25_NODEMCU_JSONCONFIG_H