Coder Social home page Coder Social logo

Comments (3)

mobizt avatar mobizt commented on May 23, 2024

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.

arlucio avatar arlucio commented on May 23, 2024

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.

mobizt avatar mobizt commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.