Skip to content

Commit

Permalink
Fix compilation error in ESP32 Core v3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Dec 5, 2024
1 parent 5a9264e commit bb1b881
Show file tree
Hide file tree
Showing 440 changed files with 37,441 additions and 753 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## We have moved to the new library

> [!WARNING]
> This library is now deprecated but no further supports for feature request.
> This library is now deprecated and end of life. No further supports for help and feature request.
> We recommended the [FirebaseClient](https://github.com/mobizt/FirebaseClient) library for ongoing supports.
> You have to read the library documentation thoroughly before use.
Expand Down
124 changes: 124 additions & 0 deletions examples/Authentications/LegacyTokenAuthen/LegacyTokenAuthen.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

/**
* Created by K. Suwatchai (Mobizt)
*
* Email: [email protected]
*
* Github: https://github.com/mobizt/Firebase-ESP-Client
*
* Copyright (c) 2023 mobizt
*
*/

/** This example will show how to authenticate using
* the legacy token or database secret with the new APIs (using config and auth data).
*/
#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#elif __has_include(<WiFiS3.h>)
#include <WiFiS3.h>
#endif

#include <Firebase_ESP_Client.h>

// Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/* 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 */
FirebaseData fbdo;

/* 4, Define the FirebaseAuth data for authentication data */
FirebaseAuth auth;

/* Define the FirebaseConfig data for config data */
FirebaseConfig config;

unsigned long dataMillis = 0;
int count = 0;

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
WiFiMulti multi;
#endif

void setup()
{

Serial.begin(115200);

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif

Serial.print("Connecting to Wi-Fi");
unsigned long ms = millis();
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

/* Assign the certificate file (optional) */
// config.cert.file = "/cert.cer";
// config.cert.file_storage = StorageType::FLASH;

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

// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
config.wifi.clearAP();
config.wifi.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif

// Comment or pass false value when WiFi reconnection will control by your code or third party library e.g. WiFiManager
Firebase.reconnectNetwork(true);

// Since v4.4.x, BearSSL engine was used, the SSL buffer need to be set.
// Large data transmission may require larger RX buffer, otherwise connection issue or data read time out can be occurred.
fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);

/* Initialize the library with the Firebase authen and config */
Firebase.begin(&config, &auth);

// Or use legacy authenticate method
// Firebase.begin(DATABASE_URL, DATABASE_SECRET);
}

void loop()
{
if (millis() - dataMillis > 5000)
{
dataMillis = millis();
Serial.printf("Set int... %s\n", Firebase.RTDB.setInt(&fbdo, "/test/int", count++) ? "ok" : fbdo.errorReason().c_str());
}
}
183 changes: 183 additions & 0 deletions examples/Authentications/ReAuthenticate/ReAuthenticate.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@

/**
* Created by K. Suwatchai (Mobizt)
*
* Email: [email protected]
*
* Github: https://github.com/mobizt/Firebase-ESP-Client
*
* Copyright (c) 2023 mobizt
*
*/

/** This example will show how to re-authenticate after signed in with Email and password.
*/
#include <Arduino.h>
#if defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#elif __has_include(<WiFiNINA.h>)
#include <WiFiNINA.h>
#elif __has_include(<WiFi101.h>)
#include <WiFi101.h>
#elif __has_include(<WiFiS3.h>)
#include <WiFiS3.h>
#endif

#include <Firebase_ESP_Client.h>

// Provide the token generation process info.
#include <addons/TokenHelper.h>

// Provide the RTDB payload printing info and other helper functions.
#include <addons/RTDBHelper.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"

/** 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
* Firebase project Web API key in Project settings, on General tab should show the
* Web API Key.
*
* You may need to enable the Identity provider at https://console.cloud.google.com/customer-identity/providers
* Select your project, click at ENABLE IDENTITY PLATFORM button.
* The API key also available by click at the link APPLICATION SETUP DETAILS.
*
*/
#define API_KEY "API_KEY"

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

#define USER_EMAIL2 "USER_EMAIL2"
#define USER_PASSWORD2 "USER_PASSWORD2"

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

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

/* 6. Define the FirebaseAuth data for authentication data */
FirebaseAuth auth;

/* 7. Define the FirebaseConfig data for config data */
FirebaseConfig config;

unsigned long dataMillis = 0;
int count = 0;
bool toggleUser = false;

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
WiFiMulti multi;
#endif

void signIn(const char *email, const char *password)
{
/* Assign the user sign in credentials */
auth.user.email = email;
auth.user.password = password;

/* Reset stored authen and config */
Firebase.reset(&config);

/* Initialize the library with the Firebase authen and config */
Firebase.begin(&config, &auth);
}

void setup()
{

Serial.begin(115200);

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
multi.addAP(WIFI_SSID, WIFI_PASSWORD);
multi.run();
#else
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#endif

Serial.print("Connecting to Wi-Fi");
unsigned long ms = millis();
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
if (millis() - ms > 10000)
break;
#endif
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);

/* Assign the api key (required) */
config.api_key = API_KEY;

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

// The WiFi credentials are required for Pico W
// due to it does not have reconnect feature.
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
config.wifi.clearAP();
config.wifi.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif

// Comment or pass false value when WiFi reconnection will control by your code or third party library e.g. WiFiManager
Firebase.reconnectNetwork(true);

// Since v4.4.x, BearSSL engine was used, the SSL buffer need to be set.
// Large data transmission may require larger RX buffer, otherwise the data read time out can be occurred.
fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);

fbdo.setResponseSize(4096);

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

/** Sign in as user 1 */
signIn(USER_EMAIL1, USER_PASSWORD1);
}

void loop()
{

// Firebase.ready() should be called repeatedly to handle authentication tasks.

if (millis() - dataMillis > 5000)
{
dataMillis = millis();

if (Firebase.ready())
{
String path = "/UsersData/";
path += auth.token.uid.c_str(); //<- user uid of current user that sign in with Emal/Password
path += "/test/int";
Serial.printf("Current UID: %s\n", auth.token.uid.c_str());
Serial.printf("Set int... %s\n", Firebase.RTDB.setInt(&fbdo, path, count++) ? "ok" : fbdo.errorReason().c_str());

// Swap users every 5 times
if (count % 5 == 0)
{
Serial.println();

if (toggleUser)
signIn(USER_EMAIL1, USER_PASSWORD1); /** Sign in as user 1 */
else
signIn(USER_EMAIL2, USER_PASSWORD2); /** Sign in as user 2 */
toggleUser = !toggleUser;
}
}
}
}
Loading

0 comments on commit bb1b881

Please sign in to comment.