Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdf18aa

Browse files
committed
Merge pull requestFirebaseExtended#51 from proppy/new-json
example/stream: use ArduinoJsonLGTM as well
2 parents74ee904 +42aa5bf commitfdf18aa

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-
constchar* method,const String& path,
69-
const String& data, HTTPClient* http) : http_(http) {
68+
constchar* 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-
constchar* method,const String& path,
79-
const String& data ="",
80-
HTTPClient* http =NULL);
78+
constchar* 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
classFirebaseStream :publicFirebaseCall {
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
boolavailable();

‎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
#defineOLED_RESET10
2526
Adafruit_SSD1306display(OLED_RESET);
@@ -47,7 +48,7 @@ void setup() {
4748
}
4849

4950

50-
voidloop() {
51+
voidloop() {
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)

[8]ページ先頭

©2009-2025 Movatter.jp