Comments (3)
The negative value returned from httpCode() is actually the client side error code which can be referred to this.
For streaming and other firebase calls which WiFi reconnection flag was set to true once in setup with Firebase.reconnectWiFi (true);
, the library will try to reconnect the WiFi if it was disconnected by call WiFi.reconnect(); internally and wait while the status was not connected for 3 seconds then check WiFi status again before exit with the error or continue.
Then you can bypass this blocking code and exit the function immediately (if the WiFi connection status was disconnected) by call Firebase.reconnectWiFi (false) in setup or somewhere that you want to toggle this option.
This is not include the 5 seconds timeout in case of WiFi was OK but no server response.
Another approach is to pause/uncaused the Firebase calls by call firebaseData.pauseFirebase(true) or firebaseData.pauseFirebase(false) to bypass (or resume) Firebase calls upon your decision from WiFi connection status.
Actually ESP8266 will try to reconnect WiFi for you already and you not need to restart ESP8266 device when you face the WiFi connection hang or device not response problem because it rather related to low free heap and other memory usage issues which you need to use, preserve and release it carefully. Do something continuously for long time without minor delay will break the internet connection too because CPU has no free time to handle WiFi task and may cause watchdog timer rimeout.
from firebase-esp8266.
Ok, important information I forgot to mention is that I'm using tzapu WiFiManager, I believe because of this I'm getting wrong http codes, even when I'm connected and everything is working httpCode() returns -4.
Using WiFi.reconnect(true) really works great, when I lose connection and it comes back, it just starts working again perfectly. My problem is just when it loses connections and the connection never comes back again. Doing some tests here and using this option (on my code) makes httpCode() always stay on -4 no matter the internet connection status.
So I tried WiFi.reconnect(false) and found out that this way httpCode goes to -5 when with no internet connection. So I made a workaround for this and it works great, gonna leave it here for anyone if looking for it in the future. I'm just starting it with reconnect(false) and when I get a httpCode -5 I put it on true until it reconnects, and then put it back to false.
This is probably just because I'm using WiFiManager and it seems like it breaks the httpCodes.
//on Setup:
errorCount=0;
WiFi.reconnect(false)
//on loop:
httpCode = firebaseData.httpCode();
if (httpCode == -5)
{
Firebase.reconnectWiFi(true);
while (httpCode == -5)
{
errorCount++;
Serial.print("Trying to reconnect. Error count: ");
Serial.println(errorCount);
delay(2000);
Firebase.pathExist(firebaseData, path); //necessary to update httpCode
httpCode = firebaseData.httpCode();
if (errorCount > 30) // restart in one minute if it don't come back (get on WiFiManager AP mode)
{
Serial.println("Restarting...");
ESP.restart();
}
}
}
else
{
Firebase.reconnectWiFi(false);
errorCount = 0;
}
Btw, thanks again for the really quick and helpful response.
from firebase-esp8266.
HTTPC_ERROR_NOT_CONNECTED or -4 for situation where WiFi connection is OK (ESP8266 was successfully connected to router or AP) but no response from server, which means no internet available, server connection was timed out, something wrong in HTTP request.
HTTPC_ERROR_CONNECTION_LOST or -5 for situation where no WiFi connection which WiFi status was the first thing to check before do anything by using basic condition checking where WiFi.status() != WL_CONNECTED. This is not guaranteed that you've connected to internet, it connected to router or AP instead.
WiFiManager does not cause any effect to Firebase library but you should check WiFi status yourself to take control the WiFi, don't let WiFiManager control this by do something that you can't track or don't know.
from firebase-esp8266.
Related Issues (20)
- ESP8266 is crashing while writing to firebase realtime database HOT 6
- ESP8266 is crashing while writing to firebase realtime database HOT 5
- soft wdt reset issue in esp8266 HOT 1
- I'm trying to read this data HOT 2
- WiFiClientSecure issue HOT 6
- Get Token status HOT 1
- issuse HOT 14
- BUG Token info: type = id token (GITKit token), status = on request HOT 1
- PLEASE HELP HOT 3
- [HELP] Cannot connect esp8266 and firebase. Compilation error: invalid conversion from 'int' to 'FirebaseConfig*' {aka 'firebase_cfg_t*'} [-fpermissive] HOT 1
- I've been getting a connection refused after a few seconds
- I've been getting a connection refused after a few seconds after connection to firebase HOT 1
- HELP : Executed HTTPS and connection Firebase HOT 2
- HELP :: captivePortal and firebase connection HOT 4
- BUG FirebaseESP8266.h with version @^4.4.12 of Library HOT 4
- FirebaseJson is confilcted with json inside ESP8266WebServer library HOT 6
- HELP
- Content Available for FCM_HTTPv1_JSON_Message HOT 1
- Unable to Fetch Data from Firebase
- Wi-Fi Reset Doesn't Initialize Firebase Variables and LED Status Doesn't Update Post-Reconnection HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-esp8266.