ESP8266 fails to reconnect to FIREBASE #388
Description
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