-
Notifications
You must be signed in to change notification settings - Fork 2
/
SensorWebConfig.h
65 lines (49 loc) · 1.6 KB
/
SensorWebConfig.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
#ifndef PM25_NODEMCU_SENSORWEBCONFIG_H
#define PM25_NODEMCU_SENSORWEBCONFIG_H
// Fingerprint:
// echo | openssl s_client -showcerts -host api.bewrosnes.org -port 443 2>/dev/null| openssl x509 -fingerprint -sha1 -noout | cut -d'=' -f 2 | tr ':' ' '
class SensorWebConfig : public JsonConfig
{
public:
double coordinates[2] = { 0.0, 0.0 };
String apiDatastreams;
String apiObservations;
String apiFingerprint;
static SensorWebConfig* getInstance();
SensorWebConfig();
private:
void parseConfig(String conf);
};
SensorWebConfig::SensorWebConfig() {
String conf = this->readConfigFile(SENSORWEB_CONFIG);
if (conf.length() > 0) {
this->parseConfig(conf);
} else {
return;
}
}
SensorWebConfig* SensorWebConfig::getInstance() {
static SensorWebConfig* _instance;
if (!_instance) {
_instance = new SensorWebConfig();
}
return _instance;
}
void SensorWebConfig::parseConfig(String conf) {
DynamicJsonBuffer jsonBuffer;
JsonObject& confRoot = jsonBuffer.parseObject(conf.c_str());
DEBUG_SERIAL("SensorWebConfig: JSON: " + conf);
if (!confRoot.success()) {
DEBUG_SERIAL("SensorWebConfig: Parsing failure");
return;
}
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->apiDatastreams = api.get<String>("datastreams");
this->apiObservations = api.get<String>("observations");
this->apiFingerprint = api.get<String>("fingerprint");
return;
}
#endif // PM25_NODEMCU_SENSORWEBCONFIG_H