Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit fdf18aa

Browse files
committed
Merge pull request #51 from proppy/new-json
example/stream: use ArduinoJson LGTM as well
2 parents 74ee904 + 42aa5bf commit fdf18aa

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

Firebase.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ FirebaseStream Firebase::stream(const String& path) {
6565

6666
// FirebaseCall
6767
FirebaseCall::FirebaseCall(const String& host, const String& auth,
68-
const char* method, const String& path,
69-
const String& data, HTTPClient* http) : http_(http) {
68+
const char* method, const String& path,
69+
const String& data, HTTPClient* http) : http_(http) {
7070
String url = makeFirebaseURL(path, auth);
7171
http_->setReuse(true);
7272
http_->begin(host, kFirebasePort, url, true, kFirebaseFingerprint);
@@ -109,8 +109,8 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
109109

110110
// FirebaseGet
111111
FirebaseGet::FirebaseGet(const String& host, const String& auth,
112-
const String& path,
113-
HTTPClient* http)
112+
const String& path,
113+
HTTPClient* http)
114114
: FirebaseCall(host, auth, "GET", path, "", http) {
115115

116116
if (!error()) {
@@ -132,8 +132,8 @@ FirebaseSet::FirebaseSet(const String& host, const String& auth,
132132
}
133133
// FirebasePush
134134
FirebasePush::FirebasePush(const String& host, const String& auth,
135-
const String& path, const String& value,
136-
HTTPClient* http)
135+
const String& path, const String& value,
136+
HTTPClient* http)
137137
: FirebaseCall(host, auth, "POST", path, value, http) {
138138
if (!error()) {
139139
// TODO: parse name
@@ -143,15 +143,15 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
143143

144144
// FirebasePush
145145
FirebaseRemove::FirebaseRemove(const String& host, const String& auth,
146-
const String& path,
147-
HTTPClient* http)
146+
const String& path,
147+
HTTPClient* http)
148148
: FirebaseCall(host, auth, "DELETE", path, "", http) {
149149
}
150150

151151
// FirebaseStream
152152
FirebaseStream::FirebaseStream(const String& host, const String& auth,
153-
const String& path,
154-
HTTPClient* http)
153+
const String& path,
154+
HTTPClient* http)
155155
: FirebaseCall(host, auth, "STREAM", path, "", http) {
156156
}
157157

Firebase.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class FirebaseCall {
7575
public:
7676
FirebaseCall() {}
7777
FirebaseCall(const String& host, const String& auth,
78-
const char* method, const String& path,
79-
const String& data = "",
80-
HTTPClient* http = NULL);
78+
const char* method, const String& path,
79+
const String& data = "",
80+
HTTPClient* http = NULL);
8181
const FirebaseError& error() const {
8282
return error_;
8383
}
@@ -94,7 +94,7 @@ class FirebaseGet : public FirebaseCall {
9494
public:
9595
FirebaseGet() {}
9696
FirebaseGet(const String& host, const String& auth,
97-
const String& path, HTTPClient* http = NULL);
97+
const String& path, HTTPClient* http = NULL);
9898

9999
const String& json() const {
100100
return json_;
@@ -122,7 +122,7 @@ class FirebasePush : public FirebaseCall {
122122
public:
123123
FirebasePush() {}
124124
FirebasePush(const String& host, const String& auth,
125-
const String& path, const String& value, HTTPClient* http = NULL);
125+
const String& path, const String& value, HTTPClient* http = NULL);
126126

127127
const String& name() const {
128128
return name_;
@@ -136,15 +136,15 @@ class FirebaseRemove : public FirebaseCall {
136136
public:
137137
FirebaseRemove() {}
138138
FirebaseRemove(const String& host, const String& auth,
139-
const String& path, HTTPClient* http = NULL);
139+
const String& path, HTTPClient* http = NULL);
140140
};
141141

142142

143143
class FirebaseStream : public FirebaseCall {
144144
public:
145145
FirebaseStream() {}
146146
FirebaseStream(const String& host, const String& auth,
147-
const String& path, HTTPClient* http = NULL);
147+
const String& path, HTTPClient* http = NULL);
148148

149149
// Return if there is any event available to read.
150150
bool available();

examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <Firebase.h>
2121
#include <Adafruit_GFX.h>
2222
#include <Adafruit_SSD1306.h>
23+
#include <ArduinoJson.h>
2324

2425
#define OLED_RESET 10
2526
Adafruit_SSD1306 display(OLED_RESET);
@@ -47,7 +48,7 @@ void setup() {
4748
}
4849

4950

50-
void loop() {
51+
void loop() {
5152
if (stream.error()) {
5253
Serial.println("streaming error");
5354
Serial.println(stream.error().message());
@@ -58,16 +59,21 @@ void loop() {
5859
auto type = stream.read(event);
5960
Serial.print("event: ");
6061
Serial.println(type);
61-
if (type != FirebaseStream::Event::UNKNOWN) {
62+
if (type == FirebaseStream::Event::PUT) {
63+
StaticJsonBuffer<200> buf;
6264
Serial.print("data: ");
6365
Serial.println(event);
66+
JsonObject& json = buf.parseObject((char*)event.c_str());
67+
String path = json["path"];
68+
float data = json["data"];
6469

6570
// TODO(proppy): parse JSON object.
6671
display.clearDisplay();
67-
display.setTextSize(1);
72+
display.setTextSize(2);
6873
display.setTextColor(WHITE);
6974
display.setCursor(0,0);
70-
display.println(event);
75+
display.println(path.c_str()+1);
76+
display.println(data);
7177
display.display();
7278
}
7379
}

0 commit comments

Comments
 (0)