-
Notifications
You must be signed in to change notification settings - Fork 2
/
AirCastingSession.h
77 lines (58 loc) · 1.71 KB
/
AirCastingSession.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
76
77
#ifndef PM25_NODEMCU_AIRCASTINGSESSION_H
#define PM25_NODEMCU_AIRCASTINGSESSION_H
class AirCastingSession : public JsonConfig
{
public:
String token;
String uuid;
static AirCastingSession* getInstance();
AirCastingSession();
bool writeToFile();
bool removeFile();
private:
void parseConfig(String conf);
};
AirCastingSession::AirCastingSession() {
String conf = this->readConfigFile(AIRCASTING_SESSION);
if (conf.length() > 0) {
this->parseConfig(conf);
} else {
return;
}
}
AirCastingSession* AirCastingSession::getInstance() {
static AirCastingSession* _instance;
if (!_instance) {
_instance = new AirCastingSession();
}
return _instance;
}
void AirCastingSession::parseConfig(String conf) {
DynamicJsonBuffer jsonBuffer;
JsonObject& confRoot = jsonBuffer.parseObject(conf.c_str());
// DEBUG_SERIAL("AirCastingSession: JSON: " + conf);
if (!confRoot.success()) {
DEBUG_SERIAL("AirCastingSession: Parsing failure");
return;
}
this->token = confRoot.get<String>("token");
this->uuid = confRoot.get<String>("uuid");
return;
}
bool AirCastingSession::writeToFile() {
// Ensure that we got something.
if (this->token.length() == 0 || this->uuid.length() == 0) {
return false;
}
DynamicJsonBuffer jsonSendBuffer;
JsonObject& root = jsonSendBuffer.createObject();
root["token"] = this->token;
root["uuid"] = this->uuid;
String jsonPayload; root.printTo(jsonPayload);
serialUdpDebug("AirCastingSession: WriteJSON: " + jsonPayload);
return safelyWriteNewFile(AIRCASTING_SESSION, jsonPayload);
}
bool AirCastingSession::removeFile() {
return safelyRemoveFile(AIRCASTING_SESSION);
}
#endif // PM25_NODEMCU_AIRCASTINGSESSION_H