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

Commitfd0f812

Browse files
committed
Merge pull requestFirebaseExtended#142 from proppy/push-type
FirebaseArduino: add typed push and set variant
2 parentsf14c6c1 +7bb1e5d commitfd0f812

File tree

4 files changed

+127
-17
lines changed

4 files changed

+127
-17
lines changed

‎examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int n = 0;
4141

4242
voidloop() {
4343
// set value
44-
Firebase.set("number",42.0);
44+
Firebase.setFloat("number",42.0);
4545
// handle error
4646
if (Firebase.failed()) {
4747
Serial.print("setting /number failed:");
@@ -51,7 +51,7 @@ void loop() {
5151
delay(1000);
5252

5353
// update value
54-
Firebase.set("number",43.0);
54+
Firebase.setFloat("number",43.0);
5555
delay(1000);
5656

5757
// get value
@@ -64,14 +64,14 @@ void loop() {
6464
delay(1000);
6565

6666
// set string value
67-
Firebase.set("message","hello world");
67+
Firebase.setString("message","hello world");
6868
delay(1000);
6969
// set bool value
70-
Firebase.set("truth",false);
70+
Firebase.setBool("truth",false);
7171
delay(1000);
7272

7373
// append a new value to /logs
74-
String name = Firebase.push("logs", n++);
74+
String name = Firebase.pushInt("logs", n++);
7575
Serial.print("pushed: /logs/");
7676
Serial.println(name);
7777
delay(1000);

‎examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ void loop() {
6868
int newButton =digitalRead(buttonPin);
6969
if (newButton != button) {
7070
button = newButton;
71-
Firebase.set("pushbutton", button);
71+
Firebase.setInt("pushbutton", button);
7272
}
7373
float newLight =analogRead(lightSensorPin);
7474
if (abs(newLight - light) >100) {
7575
light = newLight;
76-
Firebase.set("sunlight", light);
76+
Firebase.setFloat("sunlight", light);
7777
}
7878
}

‎src/FirebaseArduino.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,48 @@ void FirebaseArduino::begin(const String& host, const String& auth) {
2323
auth_ = auth;
2424
}
2525

26-
StringFirebaseArduino::FirebaseArduino::push(const String& path,const JsonVariant& value) {
26+
StringFirebaseArduino::pushInt(const String& path,int value) {
27+
returnpush(path, value);
28+
}
29+
30+
StringFirebaseArduino::pushFloat(const String& path,float value) {
31+
returnpush(path, value);
32+
}
33+
34+
StringFirebaseArduino::pushBool(const String& path,bool value) {
35+
returnpush(path, value);
36+
}
37+
38+
StringFirebaseArduino::pushString(const String& path,const String& value) {
39+
JsonVariantjson(value);
40+
returnpush(path, json);
41+
}
42+
43+
StringFirebaseArduino::push(const String& path,const JsonVariant& value) {
2744
String buf;
2845
value.printTo(buf);
2946
auto push =FirebasePush(host_, auth_, path, buf, http_.get());
3047
error_ = push.error();
3148
return push.name();
3249
}
3350

51+
voidFirebaseArduino::setInt(const String& path,int value) {
52+
set(path, value);
53+
}
54+
55+
voidFirebaseArduino::setFloat(const String& path,float value) {
56+
set(path, value);
57+
}
58+
59+
voidFirebaseArduino::setBool(const String& path,bool value) {
60+
set(path, value);
61+
}
62+
63+
voidFirebaseArduino::setString(const String& path,const String& value) {
64+
JsonVariantjson(value);
65+
set(path, json);
66+
}
67+
3468
voidFirebaseArduino::set(const String& path,const JsonVariant& value) {
3569
String buf;
3670
value.printTo(buf);

‎src/FirebaseArduino.h

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,112 @@
2323
/**
2424
* Main class for Arduino clients to interact with Firebase.
2525
* This implementation is designed to follow Arduino best practices and favor
26-
* simplicity over all else.
27-
* For more complicated usecases and more control see the Firebase class in
26+
* simplicity over all else.
27+
* For more complicated usecases and more control see the Firebase class in
2828
* Firebase.h.
2929
*/
3030
classFirebaseArduino {
3131
public:
3232
/**
33-
* Must be called first. This initialize the client with the given
33+
* Must be called first. This initialize the client with the given
3434
* firebase host and credentials.
3535
* \param host Your firebase db host, usually X.firebaseio.com.
3636
* \param auth Optional credentials for the db, a secret or token.
3737
*/
3838
voidbegin(const String& host,const String& auth ="");
3939

4040
/**
41-
*Writes data to a new child location undertheparent at path.
41+
*Appends the integer value tothenode at path.
4242
* Equivalent to the REST API's POST.
4343
* You should check success() after calling.
44-
* \param path The path inside of your db to the parent object.
45-
* \param value Data that you wish to add under the parent.
46-
* \return The unique child key where the data was written.
44+
* \param path The path of the parent node.
45+
* \param value Integer value that you wish to append to the node.
46+
* \return The unique key of the new child node.
47+
*/
48+
StringpushInt(const String& path,int value);
49+
50+
/**
51+
* Appends the float value to the node at path.
52+
* Equivalent to the REST API's POST.
53+
* You should check success() after calling.
54+
* \param path The path of the parent node.
55+
* \param value Float value that you wish to append to the node.
56+
* \return The unique key of the new child node.
57+
*/
58+
StringpushFloat(const String& path,float value);
59+
60+
/**
61+
* Appends the bool value to the node at path.
62+
* Equivalent to the REST API's POST.
63+
* You should check success() after calling.
64+
* \param path The path of the parent node.
65+
* \param value Bool value that you wish to append to the node.
66+
* \return The unique key of the new child node.
67+
*/
68+
StringpushBool(const String& path,bool value);
69+
70+
/**
71+
* Appends the String value to the node at path.
72+
* Equivalent to the REST API's POST.
73+
* You should check success() after calling.
74+
* \param path The path of the parent node.
75+
* \param value String value that you wish to append to the node.
76+
* \return The unique key of the new child node.
77+
*/
78+
StringpushString(const String& path,const String& value);
79+
80+
/**
81+
* Appends the JSON data to the node at path.
82+
* Equivalent to the REST API's POST.
83+
* You should check success() after calling.
84+
* \param path The path of the parent node.
85+
* \param value JSON data that you wish to append to the node.
86+
* \return The unique key of the new child node.
4787
*/
4888
Stringpush(const String& path,const JsonVariant& value);
4989

5090
/**
51-
* Writes thedata in value to the node located at path equivalent to the
91+
* Writes theinteger value to the node located at path equivalent to the
5292
* REST API's PUT.
5393
* You should check success() after calling.
5494
* \param path The path inside of your db to the node you wish to update.
55-
* \param value Data that you wish to write.
95+
* \param value Integer value that you wish to write.
96+
*/
97+
voidsetInt(const String& path,int value);
98+
99+
/**
100+
* Writes the float value to the node located at path equivalent to the
101+
* REST API's PUT.
102+
* You should check success() after calling.
103+
* \param path The path inside of your db to the node you wish to update.
104+
* \param value Float value that you wish to write.
105+
*/
106+
voidsetFloat(const String& path,float value);
107+
108+
/**
109+
* Writes the bool value to the node located at path equivalent to the
110+
* REST API's PUT.
111+
* You should check success() after calling.
112+
* \param path The path inside of your db to the node you wish to update.
113+
* \param value Bool value that you wish to write.
114+
*/
115+
voidsetBool(const String& path,bool value);
116+
117+
/**
118+
* Writes the String value to the node located at path equivalent to the
119+
* REST API's PUT.
120+
* You should check success() after calling.
121+
* \param path The path inside of your db to the node you wish to update.
122+
* \param value String value that you wish to write.
123+
*/
124+
voidsetString(const String& path,const String& value);
125+
126+
/**
127+
* Writes the JSON data to the node located at path.
128+
* Equivalent to the REST API's PUT.
129+
* You should check success() after calling.
130+
* \param path The path inside of your db to the node you wish to update.
131+
* \param value JSON data that you wish to write.
56132
*/
57133
voidset(const String& path,const JsonVariant& value);
58134

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp