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

Commite6bde19

Browse files
committed
Merge pull requestFirebaseExtended#34 from proppy/remove-child
remove child method
2 parents254f23a +abc0bf9 commite6bde19

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

‎Firebase.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@ Firebase& Firebase::auth(const String& auth) {
2727
return *this;
2828
}
2929

30-
Firebase&Firebase::child(const String& key) {
31-
_path = key;
32-
return *this;
33-
}
34-
35-
StringFirebase::val() {
36-
returnsendRequest("GET");
30+
StringFirebase::val(const String& path) {
31+
returnsendRequest("GET", path);
3732
}
3833

39-
StringFirebase::push(const String& value) {
40-
returnsendRequest("POST",(uint8_t*)value.c_str(), value.length());
34+
StringFirebase::push(const String&path,const String&value) {
35+
returnsendRequest("POST",path, value);
4136
}
4237

43-
Firebase&Firebase::stream() {
44-
_error.reset();
45-
String url ="/" + _path +".json";
46-
if (_auth.length() >0) {
47-
url +="?auth=" + _auth;
48-
}
38+
Firebase&Firebase::stream(const String& path) {
39+
_error.reset();
40+
String url =makeURL(path);
4941
constchar* headers[] = {"Location"};
5042
_http.setReuse(true);
5143
_http.begin(_host.c_str(), firebasePort, url.c_str(),true, firebaseFingerprint);
@@ -70,14 +62,23 @@ Firebase& Firebase::stream() {
7062
return *this;
7163
}
7264

73-
StringFirebase::sendRequest(constchar* method,uint8_t* value,size_t size) {
74-
_error.reset();
75-
String url ="/" + _path +".json";
65+
StringFirebase::makeURL(const String& path) {
66+
String url;
67+
if (path[0] !='/') {
68+
url ="/";
69+
}
70+
url += path +".json";
7671
if (_auth.length() >0) {
7772
url +="?auth=" + _auth;
7873
}
74+
return url;
75+
}
76+
77+
StringFirebase::sendRequest(constchar* method,const String& path,const String& value) {
78+
_error.reset();
79+
String url =makeURL(path);
7980
_http.begin(_host.c_str(), firebasePort, url.c_str(),true, firebaseFingerprint);
80-
int statusCode = _http.sendRequest(method, value, size);
81+
int statusCode = _http.sendRequest(method,(uint8_t*)value.c_str(), value.length());
8182
if (statusCode <0) {
8283
_error.set(statusCode,
8384
String(method) +"" + url +":"

‎Firebase.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ class Firebase {
4747
public:
4848
Firebase(const String& host);
4949
Firebase&auth(const String& auth);
50-
Firebase&child(const String& key);
5150
const FirebaseError&error()const {
5251
return _error;
5352
}
54-
Stringval();
55-
Stringpush(const String& value);
53+
Stringval(const String& path);
54+
Stringpush(const String&path,const String&value);
5655
boolconnected();
57-
Firebase&stream();
56+
Firebase&stream(const String& path);
5857
boolavailable();
5958
enum Event {
6059
UNKNOWN,
@@ -63,11 +62,11 @@ class Firebase {
6362
};
6463
Eventread(String& event);
6564
private:
66-
StringsendRequest(constchar* method,uint8_t* value =NULL,size_t size =0);
65+
StringmakeURL(const String& path);
66+
StringsendRequest(constchar* method,const String& path,const String& value ="");
6767
HTTPClient _http;
6868
String _host;
6969
String _auth;
70-
String _path;
7170
FirebaseError _error;
7271
};
7372

‎examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
#include<Firebase.h>
2121

2222
// create firebase client.
23-
Firebase logs = Firebase("example.firebaseio.com")
24-
.auth("secret_or_token")
25-
.child("child_node");
23+
Firebase fbase = Firebase("example.firebaseio.com")
24+
.auth("secret_or_token");
2625

2726
voidsetup() {
2827
Serial.begin(9600);
@@ -39,17 +38,17 @@ void setup() {
3938
Serial.println(WiFi.localIP());
4039

4140
// add a new entry.
42-
String l =logs.push("{\".sv\":\"timestamp\"}");
41+
String l =fbase.push("/logs","{\".sv\":\"timestamp\"}");
4342
// handle error.
44-
if (logs.error()) {
43+
if (fbase.error()) {
4544
Serial.println("Firebase request failed");
46-
Serial.println(logs.error().message());
45+
Serial.println(fbase.error().message());
4746
return;
4847
}
4948
// print response.
5049
Serial.println(l);
5150
// print all entries.
52-
Serial.println(logs.val());
51+
Serial.println(fbase.val("/logs"));
5352
}
5453

5554
voidloop() {

‎examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#include<Firebase.h>
2121

22-
Firebasenode = Firebase("example.firebaseio.com")
23-
.child("child_node");
22+
Firebasefbase = Firebase("example.firebaseio.com");
23+
2424
voidsetup() {
2525
Serial.begin(9600);
2626

@@ -35,18 +35,18 @@ void setup() {
3535
Serial.print("connected:");
3636
Serial.println(WiFi.localIP());
3737

38-
node.stream();
38+
fbase.stream("/chat");
3939
}
4040

4141

4242
voidloop() {
43-
if (node.error()) {
43+
if (fbase.error()) {
4444
Serial.println("streaming error");
45-
Serial.println(node.error().message());
45+
Serial.println(fbase.error().message());
4646
}
47-
if (node.available()) {
47+
if (fbase.available()) {
4848
String event;
49-
auto type =node.read(event);
49+
auto type =fbase.read(event);
5050
Serial.print("event:");
5151
Serial.println(type);
5252
if (type != Firebase::Event::UNKNOWN) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp