mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
413 stars 119 forks source link

HELP: Infinite connection loop #151

Closed Grabt234 closed 3 years ago

Grabt234 commented 3 years ago

I am currently using your code to try connect to firebase. The code works most of the time but sometimes enters into an infinite loop while waiting for "ready". Do you have any idea why firebase would not be able to connect, why it would enter an infinite loop and how one could fix it?

`void GatewayLayer4::firebaseInit() { / Assign the certificate data (optional) / //config.cert.data = rootCACert;

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

/* Assign the sevice account credentials and private key (required) */
config.service_account.data.client_email = FIREBASE_CLIENT_EMAIL;
config.service_account.data.project_id = FIREBASE_PROJECT_ID;
config.service_account.data.private_key = PRIVATE_KEY;

uint8_t selfNameArr[SENSOR_LENGTH] = {0};
uint8_t *ptr_selfNameArr = &selfNameArr[0];
selfName(ptr_selfNameArr);
std::string selfNameString = (char*)selfNameArr;

auth.token.uid = selfNameString;

/** Assign the custom claims (optional)
 * This uid will be compare to the auth.token.premium_account variable
 * (for this case) in the database rules.
*/
auth.token.claims.add("premium_account", true);
auth.token.claims.add("admin", true);

Firebase.reconnectWiFi(true);
Firebase.setReadTimeout(fbdo, 1000 * 120);
fbdo.setResponseSize(8192);

String base_path = //removed

Firebase.begin(&config, &auth);

path = base_path + auth.token.uid.c_str();

struct token_info_t info = Firebase.authTokenInfo();
String ready = "ready";
while (ready.compareTo(getTokenStatus(info)))
{
    delay(1000);
    #ifdef LL4_DEBUG_FIREBASE
    Serial.println("GatewayLayer4::firebaseSetup(): Connecting to Firebase");
    #endif
    info = Firebase.authTokenInfo();
}

}`

mobizt commented 3 years ago

I will update soon and let you know.

mobizt commented 3 years ago

The library update, v 3.8.14 is now available.

The infinite loop issue was fixed.

The callback function can be assigned for token generation as this and this.

Please update.