Skip to content

Commit

Permalink
Change the ambiguous defined macros, remove database Host requirement…
Browse files Browse the repository at this point in the history
… from other services.
  • Loading branch information
mobizt committed May 1, 2021
1 parent c84728f commit a2e7d2d
Show file tree
Hide file tree
Showing 100 changed files with 731 additions and 748 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.1.1
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v 2.1.2


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

The MIT License (MIT)

Copyright (c) 2019, 2020, 2021 K. Suwatchai (Mobizt)
Copyright (c) 2021 K. Suwatchai (Mobizt)


Permission is hereby granted, free of charge, to any person returning a copy of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

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

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

/* Assign the project host (required) */
config.host = FIREBASE_PROJECT_HOST;


/* The file systems for flash and SD/SDMMC can be changed in FirebaseFS.h. */

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

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

/** The scope of the OAuth2.0 authentication
* If you wan't this access token for others Google Cloud Services.
*/
Expand All @@ -88,7 +89,7 @@ void setup()
Firebase.reconnectWiFi(true);

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

/** Assign the maximum retry of token generation */
config.max_token_generation_retry = 5;
Expand Down Expand Up @@ -138,7 +139,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
18 changes: 10 additions & 8 deletions examples/Authentications/Anonymous_Signin/Anonymous_Signin.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 2. Define the Firebase project host name (required) */
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"

/** 3. Define the API key
/** 2. Define the API key
*
* The API key can be obtained since you created the project and set up
* the Authentication in Firebase console.
Expand All @@ -51,6 +48,9 @@
*/
#define API_KEY "API_KEY"

/* 3. If work with RTDB, define the RTDB URL */
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app

/* 4. Define the Firebase Data object */
FirebaseData fbdo;

Expand Down Expand Up @@ -82,10 +82,12 @@ void setup()
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the project host and API key (required) */
config.host = FIREBASE_PROJECT_HOST;
/* Assign the API key (required) */
config.api_key = API_KEY;

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);

Serial.println("------------------------------------");
Expand Down Expand Up @@ -121,7 +123,7 @@ void setup()
}

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

/** The id token (C++ string) will be available from config.signer.tokens.id_token
* if the sig-up was successful.
Expand Down Expand Up @@ -152,7 +154,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
18 changes: 10 additions & 8 deletions examples/Authentications/Custom_Token/Custom_Token.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 2. Define the Firebase project host name (required) */
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"

/** 3. Define the API key
/** 2. Define the API key
*
* The API key can be obtained since you created the project and set up
* the Authentication in Firebase console.
Expand All @@ -64,6 +61,9 @@
#define FIREBASE_CLIENT_EMAIL "CLIENT_EMAIL"
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----XXXXXXXXXXXX-----END PRIVATE KEY-----\n";

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

/* This is Google root CA certificate */
/*
const char rootCACert[] PROGMEM = "-----BEGIN CERTIFICATE-----\n"
Expand Down Expand Up @@ -131,8 +131,7 @@ void setup()
/* Assign the certificate data (optional) */
//config.cert.data = rootCACert;

/* Assign the project host and api key (required) */
config.host = FIREBASE_PROJECT_HOST;
/* Assign the api key (required) */
config.api_key = API_KEY;

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

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);

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

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

/** Assign the maximum retry of token generation */
config.max_token_generation_retry = 5;
Expand Down Expand Up @@ -240,7 +242,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 2. Define the Firebase project host name (required) */
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"

/** 3. Define the API key
/** 2. Define the API key
*
* The API key can be obtained since you created the project and set up
* the Authentication in Firebase console.
Expand All @@ -53,6 +50,9 @@
*/
#define API_KEY "API_KEY"

/* 3. If work with RTDB, define the RTDB URL */
#define DATABASE_URL "URL" //<databaseName>.firebaseio.com or <databaseName>.<region>.firebasedatabase.app

/** 4. Define the database secret (optional)
*
* This need only for this example to edit the database rules for you and required the
Expand Down Expand Up @@ -96,8 +96,7 @@ void setup()
//config.cert.file = "/cert.cer";
//config.cert.file_storage = mem_storage_type_flash;

/* Assign the project host and api key (required) */
config.host = FIREBASE_PROJECT_HOST;
/* Assign the api key (required) */
config.api_key = API_KEY;

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

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

/** Assign the custom claims (optional)
* This uid will be compare to the auth.token.premium_account variable
* (for this case) in the database rules.
Expand All @@ -134,7 +136,7 @@ void setup()
String base_path = "/UsersData/";

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

/** Assign the maximum retry of token generation */
config.max_token_generation_retry = 5;
Expand Down Expand Up @@ -215,7 +217,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
20 changes: 11 additions & 9 deletions examples/Authentications/Email_Password/Email_Password.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 2. Define the Firebase project host name (required) */
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"

/** 3. Define the API key
/** 2. Define the API key
*
* The API key (required) can be obtained since you created the project and set up
* the Authentication in Firebase console. Then you will get the API key from
Expand All @@ -56,10 +53,13 @@
*/
#define API_KEY "API_KEY"

/* 4. Define the user Email and password that already registerd or added in your project */
/* 3. Define the user Email and password that already registerd or added in your project */
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"

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

/** 5. Define the database secret (optional)
*
* This database secret needed only for this example to modify the database rules
Expand Down Expand Up @@ -98,21 +98,23 @@ void setup()
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the project host and api key (required) */
config.host = FIREBASE_PROJECT_HOST;
/* Assign the api key (required) */
config.api_key = API_KEY;

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

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);

String base_path = "/UsersData2/";

/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback;
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

/** Assign the maximum retry of token generation */
config.max_token_generation_retry = 5;
Expand Down Expand Up @@ -165,7 +167,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
10 changes: 5 additions & 5 deletions examples/Authentications/Legacy_Token/Legacy_Token.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

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

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

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

Firebase.reconnectWiFi(true);
Expand All @@ -93,7 +93,7 @@ void loop()
Serial.println("TYPE: " + fbdo.dataType());
Serial.println("ETag: " + fbdo.ETag());
Serial.print("VALUE: ");
printResult(fbdo);
printResult(fbdo); //see addons/RTDBHelper.h
Serial.println("------------------------------------");
Serial.println();
}
Expand Down
15 changes: 8 additions & 7 deletions examples/Authentications/Reset_Password/Reset_Password.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 2. Define the Firebase project host name (required) */
#define FIREBASE_PROJECT_HOST "PROJECT_ID.firebaseio.com"

/** 3. Define the API key
/** 2. Define the API key
*
* The API key can be obtained since you created the project and set up
* the Authentication in Firebase console.
Expand All @@ -40,9 +37,11 @@
*/
#define API_KEY "API_KEY"

/* 4. Define the user Email to reset the password */
/* 3. Define the user Email to reset the password */
#define USER_EMAIL "USER_EMAIL"

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

/* 5. Define the FirebaseConfig data for config data */
FirebaseConfig config;
Expand All @@ -65,10 +64,12 @@ void setup()
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the project host and API key (required) */
config.host = FIREBASE_PROJECT_HOST;
/* Assign the API key (required) */
config.api_key = API_KEY;

/* Assign the RTDB URL */
config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);

Serial.println("------------------------------------");
Expand Down
Loading

0 comments on commit a2e7d2d

Please sign in to comment.