firebase-arduino
firebase-arduino copied to clipboard
ESP8266 fails to reconnect to FIREBASE
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
same issue someone can help us?
for now im just using the ESP.reset();
when the connection stops. its not ideal but its keeps the ESP8266 working 24/7.
@ypegua, how does your esp knows that the connection was lost? With what line of code?
You can do this: if (Firebase.failed()) { Serial.print("setting number failed:"); Serial.println(Firebase.error()); ESP.reset(); }
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.
Me neither, its just a solution until I find the real problem.
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 .
of course!
I have the same problem, the connections fails at random times.
@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.
Same problem here. Anyone found a solution better than resetting?
I have the same error. Did anyone try to debug the library?
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(); } }
Hi @philipnguyen8588 Thank you very much for this fix. It is a life saver. King regards.
Thank you very much @philipnguyen8588 , solve the problem. Esp8266 after a while disconnect from firebase. Now my project has 3 days working fine!.
Firebase fingerprint change again E2:34:53:7A:1E:D9:7D:B8:C5:02:36:0D:B2:77:9E:5E:0F:32:71:17
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");
}
}
Thank you @felossimon !!!
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
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
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
hi, ESP.reset(); is this command work in Node mcu
hi, ESP.reset(); is this command work in Node mcu
Hi there,
ESP.reset();
works with NodeMCU.
@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
Use Mobizt library. Forget this repo!!!!!
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
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.
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?