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

Commit42aa5bf

Browse files
committed
stream: use ArduinoJson
1 parent96f7d8e commit42aa5bf

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
@@ -61,8 +61,8 @@ FirebaseStream Firebase::stream(const String& path) {
6161

6262
// FirebaseCall
6363
FirebaseCall::FirebaseCall(const String& host,const String& auth,
64-
constchar* method,const String& path,
65-
const String& data, HTTPClient* http) : http_(http) {
64+
constchar* method,const String& path,
65+
const String& data, HTTPClient* http) : http_(http) {
6666
String url =makeFirebaseURL(path, auth);
6767
http_->setReuse(true);
6868
http_->begin(host,kFirebasePort, url,true,kFirebaseFingerprint);
@@ -105,8 +105,8 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
105105

106106
// FirebaseGet
107107
FirebaseGet::FirebaseGet(const String& host,const String& auth,
108-
const String& path,
109-
HTTPClient* http)
108+
const String& path,
109+
HTTPClient* http)
110110
: FirebaseCall(host, auth,"GET", path,"", http) {
111111

112112
if (!error()) {
@@ -117,8 +117,8 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
117117

118118
// FirebasePush
119119
FirebasePush::FirebasePush(const String& host,const String& auth,
120-
const String& path,const String& value,
121-
HTTPClient* http)
120+
const String& path,const String& value,
121+
HTTPClient* http)
122122
: FirebaseCall(host, auth,"POST", path, value, http) {
123123
if (!error()) {
124124
// TODO: parse name
@@ -128,15 +128,15 @@ FirebasePush::FirebasePush(const String& host, const String& auth,
128128

129129
// FirebasePush
130130
FirebaseRemove::FirebaseRemove(const String& host,const String& auth,
131-
const String& path,
132-
HTTPClient* http)
131+
const String& path,
132+
HTTPClient* http)
133133
: FirebaseCall(host, auth,"DELETE", path,"", http) {
134134
}
135135

136136
// FirebaseStream
137137
FirebaseStream::FirebaseStream(const String& host,const String& auth,
138-
const String& path,
139-
HTTPClient* http)
138+
const String& path,
139+
HTTPClient* http)
140140
: FirebaseCall(host, auth,"STREAM", path,"", http) {
141141
}
142142

‎Firebase.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class FirebaseCall {
7373
public:
7474
FirebaseCall() {}
7575
FirebaseCall(const String& host,const String& auth,
76-
constchar* method,const String& path,
77-
const String& data ="",
78-
HTTPClient* http =NULL);
76+
constchar* method,const String& path,
77+
const String& data ="",
78+
HTTPClient* http =NULL);
7979
const FirebaseError&error()const {
8080
return error_;
8181
}
@@ -92,7 +92,7 @@ class FirebaseGet : public FirebaseCall {
9292
public:
9393
FirebaseGet() {}
9494
FirebaseGet(const String& host,const String& auth,
95-
const String& path, HTTPClient* http =NULL);
95+
const String& path, HTTPClient* http =NULL);
9696

9797
const String&json()const {
9898
return json_;
@@ -106,7 +106,7 @@ class FirebasePush : public FirebaseCall {
106106
public:
107107
FirebasePush() {}
108108
FirebasePush(const String& host,const String& auth,
109-
const String& path,const String& value, HTTPClient* http =NULL);
109+
const String& path,const String& value, HTTPClient* http =NULL);
110110

111111
const String&name()const {
112112
return name_;
@@ -120,15 +120,15 @@ class FirebaseRemove : public FirebaseCall {
120120
public:
121121
FirebaseRemove() {}
122122
FirebaseRemove(const String& host,const String& auth,
123-
const String& path, HTTPClient* http =NULL);
123+
const String& path, HTTPClient* http =NULL);
124124
};
125125

126126

127127
classFirebaseStream :publicFirebaseCall {
128128
public:
129129
FirebaseStream() {}
130130
FirebaseStream(const String& host,const String& auth,
131-
const String& path, HTTPClient* http =NULL);
131+
const String& path, HTTPClient* http =NULL);
132132

133133
// True if there is an event available.
134134
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