-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAirCastingConfig.h
75 lines (56 loc) · 1.69 KB
/
AirCastingConfig.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef PM25_NODEMCU_AIRCASTINGCONFIG_H
#define PM25_NODEMCU_AIRCASTINGCONFIG_H
class AirCastingConfig : public JsonConfig
{
public:
double coordinates[2] = { 0.0, 0.0 };
String location;
// API
String login;
String session;
String data;
// Credentials
String user;
String pass;
static AirCastingConfig* getInstance();
AirCastingConfig();
private:
void parseConfig(String conf);
};
AirCastingConfig::AirCastingConfig() {
String conf = this->readConfigFile(AIRCASTING_CONFIG);
if (conf.length() > 0) {
this->parseConfig(conf);
} else {
return;
}
}
AirCastingConfig* AirCastingConfig::getInstance() {
static AirCastingConfig* _instance;
if (!_instance) {
_instance = new AirCastingConfig();
}
return _instance;
}
void AirCastingConfig::parseConfig(String conf) {
DynamicJsonBuffer jsonBuffer;
JsonObject& confRoot = jsonBuffer.parseObject(conf.c_str());
// DEBUG_SERIAL("AirCastingConfig: JSON: " + conf);
if (!confRoot.success()) {
DEBUG_SERIAL("AirCastingConfig: Parsing failure");
return;
}
this->location = confRoot.get<String>("location");
JsonArray& coords = confRoot.get<JsonVariant>("coordinates");
this->coordinates[0] = coords.get<double>(0);
this->coordinates[1] = coords.get<double>(1);
JsonObject& api = confRoot.get<JsonVariant>("api");
this->login = api.get<String>("login");
this->session = api.get<String>("session");
this->data = api.get<String>("data");
JsonObject& creds = confRoot.get<JsonVariant>("credentials");
this->user = creds.get<String>("user");
this->pass = creds.get<String>("pass");
return;
}
#endif // PM25_NODEMCU_AIRCASTINGCONFIG_H