Skip to content

Commit a2e7d2d

Browse files
committed
Change the ambiguous defined macros, remove database Host requirement from other services.
1 parent c84728f commit a2e7d2d

File tree

100 files changed

+731
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+731
-748
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Firebase Arduino Client Library for ESP8266 and ESP32
22

33

4-
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.1.1
4+
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.1.2
55

66

77
This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
@@ -1483,7 +1483,7 @@ The result of the above code
14831483

14841484
The MIT License (MIT)
14851485

1486-
Copyright (c) 2019, 2020, 2021 K. Suwatchai (Mobizt)
1486+
Copyright (c) 2021 K. Suwatchai (Mobizt)
14871487

14881488

14891489
Permission is hereby granted, free of charge, to any person returning a copy of

examples/Authentications/Access_Token_from_File/Access_Token_from_File.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#define WIFI_SSID "WIFI_AP"
3131
#define WIFI_PASSWORD "WIFI_PASSWORD"
3232

33-
/* 2. Define the Firebase project host name (required) */
34-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
33+
/* 2. If work with RTDB, define the RTDB URL */
34+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
3535

3636
/* 3. Define the Firebase Data object */
3737
FirebaseData fbdo;
@@ -68,9 +68,7 @@ void setup()
6868
config.cert.file = "/gsr2.pem";
6969
config.cert.file_storage = mem_storage_type_flash; //or mem_storage_type_sd
7070

71-
/* Assign the project host (required) */
72-
config.host = FIREBASE_PROJECT_HOST;
73-
71+
7472
/* The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h. */
7573

7674
/* Assign the sevice account JSON file and the file storage type (required) */
@@ -80,6 +78,9 @@ void setup()
8078
/** The user UID set to empty to sign in as admin */
8179
auth.token.uid = "";
8280

81+
/* Assign the RTDB URL */
82+
config.database_url = DATABASE_URL;
83+
8384
/** The scope of the OAuth2.0 authentication
8485
* If you wan't this access token for others Google Cloud Services.
8586
*/
@@ -88,7 +89,7 @@ void setup()
8889
Firebase.reconnectWiFi(true);
8990

9091
/* Assign the callback function for the long running token generation task */
91-
config.token_status_callback = tokenStatusCallback;
92+
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
9293

9394
/** Assign the maximum retry of token generation */
9495
config.max_token_generation_retry = 5;
@@ -138,7 +139,7 @@ void loop()
138139
Serial.println("TYPE: " + fbdo.dataType());
139140
Serial.println("ETag: " + fbdo.ETag());
140141
Serial.print("VALUE: ");
141-
printResult(fbdo);
142+
printResult(fbdo); //see addons/RTDBHelper.h
142143
Serial.println("------------------------------------");
143144
Serial.println();
144145
}

examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
#define WIFI_SSID "WIFI_AP"
3737
#define WIFI_PASSWORD "WIFI_PASSWORD"
3838

39-
/* 2. Define the Firebase project host name (required) */
40-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
41-
42-
/** 3. Define the API key
39+
/** 2. Define the API key
4340
*
4441
* The API key can be obtained since you created the project and set up
4542
* the Authentication in Firebase console.
@@ -51,6 +48,9 @@
5148
*/
5249
#define API_KEY "API_KEY"
5350

51+
/* 3. If work with RTDB, define the RTDB URL */
52+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
53+
5454
/* 4. Define the Firebase Data object */
5555
FirebaseData fbdo;
5656

@@ -82,10 +82,12 @@ void setup()
8282
Serial.println(WiFi.localIP());
8383
Serial.println();
8484

85-
/* Assign the project host and API key (required) */
86-
config.host = FIREBASE_PROJECT_HOST;
85+
/* Assign the API key (required) */
8786
config.api_key = API_KEY;
8887

88+
/* Assign the RTDB URL */
89+
config.database_url = DATABASE_URL;
90+
8991
Firebase.reconnectWiFi(true);
9092

9193
Serial.println("------------------------------------");
@@ -121,7 +123,7 @@ void setup()
121123
}
122124

123125
/* Assign the callback function for the long running token generation task */
124-
config.token_status_callback = tokenStatusCallback;
126+
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
125127

126128
/** The id token (C++ string) will be available from config.signer.tokens.id_token
127129
* if the sig-up was successful.
@@ -152,7 +154,7 @@ void loop()
152154
Serial.println("TYPE: " + fbdo.dataType());
153155
Serial.println("ETag: " + fbdo.ETag());
154156
Serial.print("VALUE: ");
155-
printResult(fbdo);
157+
printResult(fbdo); //see addons/RTDBHelper.h
156158
Serial.println("------------------------------------");
157159
Serial.println();
158160
}

examples/Authentications/Custom_Token/Custom_Token.ino

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
#define WIFI_SSID "WIFI_AP"
3939
#define WIFI_PASSWORD "WIFI_PASSWORD"
4040

41-
/* 2. Define the Firebase project host name (required) */
42-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
43-
44-
/** 3. Define the API key
41+
/** 2. Define the API key
4542
*
4643
* The API key can be obtained since you created the project and set up
4744
* the Authentication in Firebase console.
@@ -64,6 +61,9 @@
6461
#define FIREBASE_CLIENT_EMAIL "CLIENT_EMAIL"
6562
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----XXXXXXXXXXXX-----END PRIVATE KEY-----\n";
6663

64+
/* 4. If work with RTDB, define the RTDB URL */
65+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
66+
6767
/* This is Google root CA certificate */
6868
/*
6969
const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n"
@@ -131,8 +131,7 @@ void setup()
131131
/* Assign the certificate data (optional) */
132132
//config.cert.data = rootCACert;
133133

134-
/* Assign the project host and api key (required) */
135-
config.host = FIREBASE_PROJECT_HOST;
134+
/* Assign the api key (required) */
136135
config.api_key = API_KEY;
137136

138137
/* Assign the sevice account credentials and private key (required) */
@@ -161,14 +160,17 @@ void setup()
161160
auth.token.claims.add("premium_account", true);
162161
auth.token.claims.add("admin", true);
163162

163+
/* Assign the RTDB URL */
164+
config.database_url = DATABASE_URL;
165+
164166
Firebase.reconnectWiFi(true);
165167
fbdo.setResponseSize(4096);
166168

167169
/* path for user data is now "/UsersData/Node1" */
168170
String base_path = "/UsersData/";
169171

170172
/* Assign the callback function for the long running token generation task */
171-
config.token_status_callback = tokenStatusCallback;
173+
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
172174

173175
/** Assign the maximum retry of token generation */
174176
config.max_token_generation_retry = 5;
@@ -240,7 +242,7 @@ void loop()
240242
Serial.println("TYPE: " + fbdo.dataType());
241243
Serial.println("ETag: " + fbdo.ETag());
242244
Serial.print("VALUE: ");
243-
printResult(fbdo);
245+
printResult(fbdo); //see addons/RTDBHelper.h
244246
Serial.println("------------------------------------");
245247
Serial.println();
246248
}

examples/Authentications/Custom_Token_from_File/Custom_Token_from_File.ino

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
#define WIFI_SSID "WIFI_AP"
3939
#define WIFI_PASSWORD "WIFI_PASSWORD"
4040

41-
/* 2. Define the Firebase project host name (required) */
42-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
43-
44-
/** 3. Define the API key
41+
/** 2. Define the API key
4542
*
4643
* The API key can be obtained since you created the project and set up
4744
* the Authentication in Firebase console.
@@ -53,6 +50,9 @@
5350
*/
5451
#define API_KEY "API_KEY"
5552

53+
/* 3. If work with RTDB, define the RTDB URL */
54+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
55+
5656
/** 4. Define the database secret (optional)
5757
*
5858
* This need only for this example to edit the database rules for you and required the
@@ -96,8 +96,7 @@ void setup()
9696
//config.cert.file = "/cert.cer";
9797
//config.cert.file_storage = mem_storage_type_flash;
9898

99-
/* Assign the project host and api key (required) */
100-
config.host = FIREBASE_PROJECT_HOST;
99+
/* Assign the api key (required) */
101100
config.api_key = API_KEY;
102101

103102
/* The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h. */
@@ -120,6 +119,9 @@ void setup()
120119
*/
121120
auth.token.uid = "Node1";
122121

122+
/* Assign the RTDB URL */
123+
config.database_url = DATABASE_URL;
124+
123125
/** Assign the custom claims (optional)
124126
* This uid will be compare to the auth.token.premium_account variable
125127
* (for this case) in the database rules.
@@ -134,7 +136,7 @@ void setup()
134136
String base_path = "/UsersData/";
135137

136138
/* Assign the callback function for the long running token generation task */
137-
config.token_status_callback = tokenStatusCallback;
139+
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
138140

139141
/** Assign the maximum retry of token generation */
140142
config.max_token_generation_retry = 5;
@@ -215,7 +217,7 @@ void loop()
215217
Serial.println("TYPE: " + fbdo.dataType());
216218
Serial.println("ETag: " + fbdo.ETag());
217219
Serial.print("VALUE: ");
218-
printResult(fbdo);
220+
printResult(fbdo); //see addons/RTDBHelper.h
219221
Serial.println("------------------------------------");
220222
Serial.println();
221223
}

examples/Authentications/Email_Password/Email_Password.ino

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
#define WIFI_SSID "WIFI_AP"
4040
#define WIFI_PASSWORD "WIFI_PASSWORD"
4141

42-
/* 2. Define the Firebase project host name (required) */
43-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
44-
45-
/** 3. Define the API key
42+
/** 2. Define the API key
4643
*
4744
* The API key (required) can be obtained since you created the project and set up
4845
* the Authentication in Firebase console. Then you will get the API key from
@@ -56,10 +53,13 @@
5653
*/
5754
#define API_KEY "API_KEY"
5855

59-
/* 4. Define the user Email and password that already registerd or added in your project */
56+
/* 3. Define the user Email and password that already registerd or added in your project */
6057
#define USER_EMAIL "USER_EMAIL"
6158
#define USER_PASSWORD "USER_PASSWORD"
6259

60+
/* 4. If work with RTDB, define the RTDB URL */
61+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
62+
6363
/** 5. Define the database secret (optional)
6464
*
6565
* This database secret needed only for this example to modify the database rules
@@ -98,21 +98,23 @@ void setup()
9898
Serial.println(WiFi.localIP());
9999
Serial.println();
100100

101-
/* Assign the project host and api key (required) */
102-
config.host = FIREBASE_PROJECT_HOST;
101+
/* Assign the api key (required) */
103102
config.api_key = API_KEY;
104103

105104
/* Assign the user sign in credentials */
106105
auth.user.email = USER_EMAIL;
107106
auth.user.password = USER_PASSWORD;
108107

108+
/* Assign the RTDB URL */
109+
config.database_url = DATABASE_URL;
110+
109111
Firebase.reconnectWiFi(true);
110112
fbdo.setResponseSize(4096);
111113

112114
String base_path = "/UsersData2/";
113115

114116
/* Assign the callback function for the long running token generation task */
115-
config.token_status_callback = tokenStatusCallback;
117+
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
116118

117119
/** Assign the maximum retry of token generation */
118120
config.max_token_generation_retry = 5;
@@ -165,7 +167,7 @@ void loop()
165167
Serial.println("TYPE: " + fbdo.dataType());
166168
Serial.println("ETag: " + fbdo.ETag());
167169
Serial.print("VALUE: ");
168-
printResult(fbdo);
170+
printResult(fbdo); //see addons/RTDBHelper.h
169171
Serial.println("------------------------------------");
170172
Serial.println();
171173
}

examples/Authentications/Legacy_Token/Legacy_Token.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#define WIFI_SSID "WIFI_AP"
2828
#define WIFI_PASSWORD "WIFI_PASSWORD"
2929

30-
/* 2. Define the Firebase project host name (required) */
31-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
30+
/* 2. If work with RTDB, define the RTDB URL and database secret */
31+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
3232
#define DATABASE_SECRET "DATABASE_SECRET"
3333

3434
/* 3. Define the Firebase Data object */
@@ -65,8 +65,8 @@ void setup()
6565
//config.cert.file = "/cert.cer";
6666
//config.cert.file_storage = StorageType::FLASH;
6767

68-
/* Assign the project host and database secret(required) */
69-
config.host = FIREBASE_PROJECT_HOST;
68+
/* Assign the database URL and database secret(required) */
69+
config.database_url = DATABASE_URL;
7070
config.signer.tokens.legacy_token = DATABASE_SECRET;
7171

7272
Firebase.reconnectWiFi(true);
@@ -93,7 +93,7 @@ void loop()
9393
Serial.println("TYPE: " + fbdo.dataType());
9494
Serial.println("ETag: " + fbdo.ETag());
9595
Serial.print("VALUE: ");
96-
printResult(fbdo);
96+
printResult(fbdo); //see addons/RTDBHelper.h
9797
Serial.println("------------------------------------");
9898
Serial.println();
9999
}

examples/Authentications/Reset_Password/Reset_Password.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
#define WIFI_SSID "WIFI_AP"
2626
#define WIFI_PASSWORD "WIFI_PASSWORD"
2727

28-
/* 2. Define the Firebase project host name (required) */
29-
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"
30-
31-
/** 3. Define the API key
28+
/** 2. Define the API key
3229
*
3330
* The API key can be obtained since you created the project and set up
3431
* the Authentication in Firebase console.
@@ -40,9 +37,11 @@
4037
*/
4138
#define API_KEY "API_KEY"
4239

43-
/* 4. Define the user Email to reset the password */
40+
/* 3. Define the user Email to reset the password */
4441
#define USER_EMAIL "USER_EMAIL"
4542

43+
/* 4. If work with RTDB, define the RTDB URL */
44+
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app
4645

4746
/* 5. Define the FirebaseConfig data for config data */
4847
FirebaseConfig config;
@@ -65,10 +64,12 @@ void setup()
6564
Serial.println(WiFi.localIP());
6665
Serial.println();
6766

68-
/* Assign the project host and API key (required) */
69-
config.host = FIREBASE_PROJECT_HOST;
67+
/* Assign the API key (required) */
7068
config.api_key = API_KEY;
7169

70+
/* Assign the RTDB URL */
71+
config.database_url = DATABASE_URL;
72+
7273
Firebase.reconnectWiFi(true);
7374

7475
Serial.println("------------------------------------");

0 commit comments

Comments
 (0)