FirebaseExtended / firebase-arduino

Arduino samples for Firebase.
Apache License 2.0
943 stars 494 forks source link

Firebase was not reconnecting ESP8266 #437

Open stechome opened 5 years ago

stechome commented 5 years ago

Once the internet connection is disconnected, it's wired again. When I'm wired again, firebase does not connect. So when the problem is wired again, it's not connected to firebasis again. How do I do that?

`boolean WiFiReturns() { if (WiFi.localIP() == IPAddress(0, 0, 0, 0)) return 0; switch (WiFi.status()) { case WL_NO_SHIELD: return 0; case WL_IDLE_STATUS: return 0; case WL_NO_SSID_AVAIL: return 0; case WL_SCAN_COMPLETED: return 1; case WL_CONNECTED: return 1; case WL_CONNECT_FAILED: return 0; case WL_CONNECTION_LOST: return 0; case WL_DISCONNECTED: return 0; default: return 0; } } void firebasereconnect() { Serial.println("Trying to reconnect"); Firebase.begin(firebaseURl, authCode); } void loop() {

if (!WiFiReturns()) { WiFi.isConnected(); digitalWrite(WIFILED, HIGH); firebasereconnect();

} else { digitalWrite(WIFILED, LOW); } }`

TrickSumo commented 5 years ago

Hi

I am also facing the same issue. I am using ESP.reset as a temporary remedy.

Though it does not fully resolve the problem but ESP.reset(); helps to reconnect to firebase.

// header

int count =0;

void setup{// wifi etc.}

void loop()
{

  if (Firebase.failed())
  {
    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
    Serial.println(Firebase.error());
    delay(10);
    Serial.println("Error connecting firebase!");
    count++;
    if (count == 10) {
      count = 0;
      ESP.reset();
    }

  return;
  }
FrankAndYoung commented 5 years ago

I can't seem to set or push any value to firebase from NodeMCU that worked a month ago. Does anyone has the same problem? Is the fingerprint of the firebase changed again?

Edit: NVM firebase changed their fingerprint to B6:F5:80:C8:B1:DA:61:C1:07:9D:80:42:D8:A9:1F:AF:9F:C8:96:7D for anyone who has the problem connecting, go to firebase-arduino-master/src/FirebaseHttpClient.h and change kFirebaseFingerprint[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

nheoo commented 5 years ago

error stream :((

FrankAndYoung commented 5 years ago

I installed the Version 5.13.4 of ArduinoJson library, the newer versions seems to not work for NodeMCU

TrickSumo commented 5 years ago

Hi

ArduinoJson 6.0 is not compatible with firebase-arduino right now.

This one will work:-

https://github.com/bblanchon/ArduinoJson/tree/5.x

nikrath commented 5 years ago

@FrankAndYoung Hey frank, how do you check the fingerprint of firebase? I used the GRC website (https://www.grc.com/fingerprints.htm) to check and I got a different fingerprint for console.firebase.google.com than what you have got. The fingerprint you gave worked, but the one I found did not work.

FrankAndYoung commented 5 years ago

Oh you dont enter the actual url, instead you enter the host reference to your realtime database For example #define FIREBASE_HOST "example.firebaseio.com" in the FirebaseDemo, it will be "example.firebaseio.com".

nikrath commented 5 years ago

@FrankAndYoung Thanks a lot Frank! It worked

ironaraujo commented 5 years ago

It Works... @FrankAndYoung Thank you. Do you know if will be necessary to rebuild to all devices every time it occurs? Does it happen that often?

TrickSumo commented 5 years ago

Hi @ironaraujo

Yes, it is necessary to rebuild all devices after fingerprint update.

It happens everytime whenever firebase server SSL certificate renewed.

ironaraujo commented 5 years ago

@TrickSumo Is there anyway to avoid that?

TrickSumo commented 5 years ago

This library does not use fingerprint to connect to firebase:-

https://github.com/mobizt/Firebase-ESP8266

nheoo commented 5 years ago

Two days I did everything to connect to the firebase but I couldn't connect. below is my code. Looking for help plz:

include

include

define LedPin 16

define FIREBASE_HOST "nodemculed-32c6b.firebaseio.com"

define FIREBASE_AUTH "E7R2aboxbpvddXEDY9MBPLxyU2b4ZfNWtOpqXoLs"

define WIFI_SSID "conmabachbach"

define WIFI_PASSWORD "dung3gdi"

void setup() { pinMode(LedPin, OUTPUT); Serial.begin(115200); // connect to wifi. WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("connecting"); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(); Serial.print("connected: ") ; Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); Firebase.stream("/Myhome"); } void loop() { if (Firebase.failed()) { Serial.println("streaming error"); Serial.println(Firebase.error()); }

if (Firebase.available()) { FirebaseObject event = Firebase.readEvent(); String eventType = event.getString("type"); Serial.print("event: "); Serial.println(eventType); if (eventType == "put") { String path = event.getString("path"); String data = event.getString("data"); Serial.println(String("data: ") + data); if (path.equals("/light/value")) { if (data.equals("off")) { digitalWrite(LedPin, HIGH); } else { digitalWrite(LedPin, LOW); } } } } }

ironaraujo commented 5 years ago

@TrickSumo This libs is awesome. It recovers from internet disconnection and firebase stream time out. Ty.

ironaraujo commented 5 years ago

@nheoo Check if your Arduino Library is updated, google fingerprint have change a couple days ago. So I would reinstall Arduino lib, if you want continue using that one...

I also would add an delay(1000) immediately after "Firebase.stream("/Myhome");" in setup. It will give more time to estabilish the connection.

TrickSumo commented 5 years ago

@ironaraujo

Yes, that library is awesome.

Thanks to @mobizt

nheoo commented 5 years ago

@nheoo Check if your Arduino Library is updated, google fingerprint have change a couple days ago. So I would reinstall Arduino lib, if you want continue using that one...

I also would add an delay(1000) immediately after "Firebase.stream("/Myhome");" in setup. It will give more time to estabilish the connection.

thank u <3 I knew my problem. Are there any i/o pins to declare that I can use?

AzwadAbid commented 5 years ago

@FrankAndYoung Thanks man! It solved the problem for me.

kevalshah1223 commented 5 years ago

not able to connect NodeMCU to firebase right now help me please

kevalshah1223 commented 5 years ago

can see any value which is fetched from a database from firebase to nodemcu