-
Notifications
You must be signed in to change notification settings - Fork 33
/
IOXhop_FirebaseStream.h
75 lines (58 loc) · 1.37 KB
/
IOXhop_FirebaseStream.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 _IOXhop_FirebaseStream_H_INCLUDED
#define _IOXhop_FirebaseStream_H_INCLUDED
#include <Arduino.h>
#include <ArduinoJson.h>
#define STREAM_JSON_BUFFER_SIZE 1024
#define STREAM_JSON_DATA_BUFFER_SIZE 1024
class FirebaseStream {
public:
FirebaseStream(String event, String data) {
_event = event;
StaticJsonBuffer<STREAM_JSON_BUFFER_SIZE> jsonBuffer;
JsonObject &root = jsonBuffer.parseObject(data);
if (root.success()) {
if (root.containsKey("path") && root.containsKey("data")) {
_path = root["path"].as<String>();
_data = root["data"].as<String>();
}
}
}
String getEvent() {
return _event;
}
String getPath() {
return _path;
}
int getDataInt() {
return _data.toInt();
}
float getDataFloat() {
return _data.toFloat();
}
String getDataString() {
return _data;
}
float getDataBool() {
return _data.indexOf("true") >= 0;
}
void getData(int &value) {
value = getDataInt();
}
void getData(float &value) {
value = getDataFloat();
}
void getData(String &value) {
value = getDataString();
}
void getData(bool &value) {
value = getDataBool();
}
JsonVariant getData() {
return StaticJsonBuffer<STREAM_JSON_DATA_BUFFER_SIZE>().parseObject(_data);
}
private:
String _event, _path, _data = "";
bool _dataError = false, _begin = false;
}
;
#endif