-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNtpConfig.h
56 lines (42 loc) · 1.07 KB
/
NtpConfig.h
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
#ifndef PM25_NODEMCU_NTPCONFIG_H
#define PM25_NODEMCU_NTPCONFIG_H
class NtpConfig : public JsonConfig
{
public:
String ntpServer;
double ntpTZOffset;
bool ntpDayLight;
static NtpConfig* getInstance();
NtpConfig();
private:
void parseConfig(String conf);
};
NtpConfig::NtpConfig() {
String conf = this->readConfigFile(NTP_CONFIG);
if (conf.length() > 0) {
this->parseConfig(conf);
} else {
return;
}
}
NtpConfig* NtpConfig::getInstance() {
static NtpConfig* _instance;
if (!_instance) {
_instance = new NtpConfig();
}
return _instance;
}
void NtpConfig::parseConfig(String conf) {
DynamicJsonBuffer jsonBuffer;
JsonObject& confRoot = jsonBuffer.parseObject(conf.c_str());
DEBUG_SERIAL("NtpConfig: JSON: " + conf);
if (!confRoot.success()) {
DEBUG_SERIAL("NtpConfig: Parsing failure");
return;
}
this->ntpServer = confRoot.get<String>("server");
this->ntpTZOffset = confRoot.get<double>("tzoffset");
this->ntpDayLight = confRoot.get<bool>("daylight");
return;
}
#endif // PM25_NODEMCU_NTPCONFIG_H