Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

ESP8266 fails to reconnect to FIREBASE #388

Open
ypegua opened this issue Nov 8, 2018 · 28 comments
Open

ESP8266 fails to reconnect to FIREBASE #388

ypegua opened this issue Nov 8, 2018 · 28 comments

Comments

@ypegua
Copy link

ypegua commented Nov 8, 2018

When i turn on the ESP8266 everything works fine for a while, until the connection with firebase for some reason stops, and im having problems reconnecting to firebase again. Can somebody give me an idea to solve this? without manually reseting the ESP8266 (witch kills the purpose of the ESP8266)

this is my code:

`#include <ESP8266WiFi.h>
#include<FirebaseArduino.h>

#define FIREBASE_HOST "XXXXXXX.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "" and "/"
#define FIREBASE_AUTH "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" //Your Firebase Database Secret goes here

#define WIFI_SSID "wifi" //your WiFi SSID for which yout NodeMCU connects
#define WIFI_PASSWORD "XXXXX"//Password of your wifi network

String varCooler;

#define Cooler 14 //D5
int val2;

void setup()
{
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor

pinMode(Cooler,OUTPUT);

digitalWrite(Cooler,HIGH);

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);
varCooler = Firebase.getString("Cooler");
Firebase.setString("Cooler","1");
Firebase.setString("Cooler",varCooler);
}

void firebasereconnect()
{
Serial.println("Trying to reconnect");
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{

if (Firebase.failed())
{
Serial.print("setting number failed:");
Serial.println(Firebase.error());
firebasereconnect();
return;
}

val2=Firebase.getString("Cooler").toInt(); //Reading the value of the varialble Status from the firebase

if(val2==1) // If, the Status is 1, turn on the Relay2
{
digitalWrite(Cooler,HIGH);
Serial.println("Cooler OFF");
}
else if(val2==0) // If, the Status is 0, turn Off the Relay2
{
digitalWrite(Cooler,LOW);
Serial.println("Cooler ON");
}

}`

Cooler is just variable that is use for output

@josacore2017
Copy link

same issue someone can help us?

@ypegua
Copy link
Author

ypegua commented Nov 10, 2018

for now im just using the ESP.reset(); when the connection stops. its not ideal but its keeps the ESP8266 working 24/7.

@MrSuhov
Copy link

MrSuhov commented Nov 10, 2018

@ypegua, how does your esp knows that the connection was lost? With what line of code?

@ypegua
Copy link
Author

ypegua commented Nov 10, 2018

You can do this:
if (Firebase.failed())
{
Serial.print("setting number failed:");
Serial.println(Firebase.error());
ESP.reset();
}

@MrSuhov
Copy link

MrSuhov commented Nov 10, 2018

Unfortunately, in my case I got empty Firebase.error() in about 10 minutes, however I still can update values to the firebase. So in my case Firebase.error() does not mean the connection was lost. And I don't want to reboot my esp every 10 min.

@ypegua
Copy link
Author

ypegua commented Nov 10, 2018

Me neither, its just a solution until I find the real problem.

@josacore2017
Copy link

yep it work thx for ESP.reset(); solution but it takes time to reset 2 seconds. but it works, if you find the solution please share it , i do the same .

@ypegua
Copy link
Author

ypegua commented Nov 10, 2018

of course!

@JanChodorowski
Copy link

I have the same problem, the connections fails at random times.

@JanChodorowski
Copy link

@ypegua Firebase.begin() only sets the strings inside of the Firebase object, so effectively does nothing, since the values are the same. It DOES NOT RECONNECT.

void FirebaseArduino::begin(const String& host, const String& auth) { host_ = host.c_str(); auth_ = auth.c_str(); }

What's more when I used that in loop() it caused the streaming to fail, not sure yet why.

@gedeondt
Copy link

Same problem here. Anyone found a solution better than resetting?

@hugolimachaves
Copy link

I have the same error. Did anyone try to debug the library?

@philipnguyen8588
Copy link

philipnguyen8588 commented Jan 25, 2019

I have the same error. Did anyone try to debug the library?

I found the error in the library Firebase.cpp => void FirebaseCall::analyzeError
You should change this code
Before

void FirebaseCall::analyzeError(char* method, int status, const std::string& path_with_auth) {
if (status != 200) {
error_ = FirebaseError(status,
std::string(method) + " " + path_with_auth +
": " + http_->errorToString(status));
}
}

After

void FirebaseCall::analyzeError(char* method, int status, const std::string& path_with_auth) {
if (status != 200) {
error_ = FirebaseError(status,
std::string(method) + " " + path_with_auth +
": " + http_->errorToString(status));
} else {
error_ = FirebaseError();
}
}

@mikrodunya
Copy link

Hi @philipnguyen8588
Thank you very much for this fix. It is a life saver.
King regards.

@felossimon
Copy link

Thank you very much @philipnguyen8588 , solve the problem. Esp8266 after a while disconnect from firebase. Now my project has 3 days working fine!.

@felossimon
Copy link

Firebase fingerprint change again
E2:34:53:7A:1E:D9:7D:B8:C5:02:36:0D:B2:77:9E:5E:0F:32:71:17

@MINDMAPPERZ
Copy link

Hello Folks,
I want to make a Home Automation Project with ESP3212 but it takes too much time (execution time is too high) when we give a command.
Please give me a solution.
Why is that, and how can I fix it?

#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>

#define WIFI_SSID "yyyy"
#define WIFI_PASSWORD "xxxxxxxxxx"

#define Relay1 25 //D
int val1;

#define Relay2 26 //D
int val2;

#define Relay3 27 //D
int val3;

#define Relay4 14 //D

void setup()
{
Serial.begin(115200);
pinMode(Relay1,OUTPUT);
pinMode(Relay2,OUTPUT);
pinMode(Relay3,OUTPUT);
pinMode(Relay4,OUTPUT);

digitalWrite(Relay1,HIGH);
digitalWrite(Relay2,HIGH);
digitalWrite(Relay3,HIGH);
digitalWrite(Relay4,HIGH);

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("xyz","zyx");
WiFi.setAutoReconnect(true);
}

void firebasereconnect()
{
Serial.println("Trying to reconnect");
Firebase.begin( "xyz", "zyx");
delay(1000);
}

void loop()
{
Firebase.setString("FILE_NAME", "ASIF");

   if (Firebase.failed())
  {
    
  Serial.print("setting number failed:");
  Serial.println(Firebase.error());
  firebasereconnect();
  return;
}

val1=Firebase.getString("S1").toInt(); //Reading the value of the varialble Status from the firebase

if(val1==1) // If, the Status is 1, turn on the Relay1
{
digitalWrite(Relay1,LOW);
Serial.println("LIGHT ON");
}
else if(val1==0) // If, the Status is 0, turn Off the Relay1
{
digitalWrite(Relay1,HIGH);
Serial.println("LIGHT OFF");
}

val2=Firebase.getString("S2").toInt(); //Reading the value of the varialble Status from the firebase

if(val2==1) // If, the Status is 1, turn on the Relay2
{
digitalWrite(Relay2,LOW);
Serial.println("AC ON");
}
else if(val2==0) // If, the Status is 0, turn Off the Relay2
{
digitalWrite(Relay2,HIGH);
Serial.println("AC OFF");
}

val3=Firebase.getString("S3").toInt(); //Reading the value of the varialble Status from the firebase

if(val3==1) // If, the Status is 1, turn on the Relay3
{
digitalWrite(Relay3,LOW);
Serial.println("FAN ON");
}
else if(val3==0) // If, the Status is 0, turn Off the Relay3
{
digitalWrite(Relay3,HIGH);
Serial.println("FAN OFF");
}

val4=Firebase.getString("S4").toInt(); //Reading the value of the varialble Status from the firebase

if(val4==1) // If, the Status is 1, turn on the Relay4
{
digitalWrite(Relay4,LOW);
Serial.println("GEYSER ON");
}
else if(val4==0) // If, the Status is 0, turn Off the Relay4
{
digitalWrite(Relay4,HIGH);
Serial.println("GEYSER OFF");
}

}

@ghareisa
Copy link

Thank you @felossimon !!!

@ghareisa
Copy link

To find current firebase fingerprint, go to your firebase page with ./json
https://xxxxxxxxx.firebaseio.com/.json
Click on the lock symbol and open the certificate, then at the very end there is the SHA-1 Fingerprint

Reference:
https://medium.com/@o.lourme/our-iot-journey-through-esp8266-firebase-angular-and-plotly-js-part-1-a07db495ac5f

@TrickSumo
Copy link
Contributor

TrickSumo commented Mar 11, 2019

Hi there,

Use this site to find fingerprint:- https://www.grc.com/fingerprints.htm

Steps to update fingerprints:-

  • Right now fingerprint is:- E2 34 53 7A 1E D9 7D B8 C5 02 36 0D B2 77 9E 5E 0F 32 71 17

  • So, go to "C:\Users\user-name\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient.h"

  • Update fingerprint:-

static const char kFirebaseFingerprint[] =
"E2 34 53 7A 1E D9 7D B8 C5 02 36 0D B2 77 9E 5E 0F 32 71 17";

Done :)

Thanks

@beaconIOT
Copy link

Is anyone still having this issue? Even after updating to the most recent commit of the Firebase library and changing the Firebase.cpp file as per @philipnguyen8588 's suggestion, I'm still having a reconnection issue. My ESP8266 will stay connected to Firebase for anywhere between 6 - 24 hours, but then will always at some point have a Firebase connection drop and it won't reconnect.

I have confirmed that WiFi is still connected on the ESP8266, it's just the Firebase connection that has the issue. Also, I can't use the ESP.Reset() function when there is a drop, because I use the D0 pin for a sensor on my PCB and sometimes it's low or high depending on the sensor (I think D0 needs to be high during a reset, right?)

Any insight would be amazing

@pkptissera080
Copy link

hi,
ESP.reset(); is this command work in Node mcu

@TrickSumo
Copy link
Contributor

hi,
ESP.reset(); is this command work in Node mcu

Hi there,

ESP.reset(); works with NodeMCU.

kotl added a commit that referenced this issue Apr 19, 2019
Fix issue #388 ESP8266 fails to reconnect to FIREBASE #388
@alvaroaguero55
Copy link

@philipnguyen8588 it is possible to fix the error of firebase reconnection (editing the FirebaseESP8266.cpp file) in Firebase version of Mobizt? https://github.com/mobizt/Firebase-ESP8266

@Gizmodo
Copy link

Gizmodo commented Aug 17, 2019

Use Mobizt library. Forget this repo!!!!!

@ghost
Copy link

ghost commented Feb 19, 2020

I am getting an error
Invalid library found in C:\Users\ukesr\OneDrive\Documents\Arduino\libraries\Firebase_ESP8266_Client: no headers files (.h) found in C:\Users\ukesr\OneDrive\Documents\Arduino\libraries\Firebase_ESP8266_Client
Can anyone please help me

@doublejosh
Copy link

Ironically I came here because I'm having this problem with the Firebase_ESP8266 library.

Pushing data and getting values is fine, including using Firebase.getShallowData ...however Firebase.getJSON can be very unforgiving/flakey. In my case, it seems to be an SPI/serial clash. Still debugging, but it's been days.

@yusufsakr
Copy link

I am using "Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32" but i couldn't find this function in the .cpp file
or this is a different liberary?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests