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
415 stars 118 forks source link

Intermittent "Connection Refused" Error with Firebase ESP32 Library #292

Closed Helmar0 closed 1 year ago

Helmar0 commented 1 year ago

Hello,

I am experiencing intermittent "Connection Refused" errors when using the Firebase ESP32 library (version 4.4.8) to update data in the Firebase Realtime Database. The issue seems to occur sporadically and is not consistently reproducible.

I am using an ESP32 development board (specifically, the ESP32 Lolin D32 Pro) and Arduino IDE 2.2.1. My Firebase JSON structure is relatively simple and does not have any complex nesting.

Here is an example of the code I am using to update Firebase data:

include

// ...

FirebaseJson jsontest; FirebaseData fbdo; FirebaseAuth auth; FirebaseConfig config;

// ...

config.database_url = FIREBASE_HOST; config.signer.tokens.legacy_token = FIREBASE_AUTH; Firebase.begin(&config, &auth); Firebase.reconnectWiFi(true); Firebase.setMaxRetry(fbdo, 3); Firebase.setMaxErrorQueue(fbdo, 30); fbdo.setResponseSize(8192);

jsontest.clear(); // ... Setting various Firebase values ...

if (Firebase.updateNode(fbdo, "test", jsontest)) { Serial.println(" ---> test PASSED: updateNode!"); } else { Serial.println(" ---> REASON: " + fbdo.errorReason()); }

// ...

While the connection works most of the time, there are instances when it returns "Connection Refused." However, if I reset the ESP32 and establish a new connection, the issue disappears temporarily.

I have also attempted to create a new FirebaseData object (fbdo) before each update, but the problem persists, suggesting that it may not be related to the fbdo object itself.

Is there a way to reset or re-establish the Firebase connection without resetting the entire ESP32? I am wondering if there might be an issue related to WiFi connection state or socket management that could be causing this problem.

Thank you for your assistance. I appreciate your help in resolving this issue.

Best regards, Helmar Alvares

mobizt commented 1 year ago

You should follow the new example for v4.4.x. https://github.com/mobizt/Firebase-ESP32/blob/9f264df8c996c3f4515293b1f34e2725c0b68cc1/examples/Basic/Basic.ino#L84-L86