So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Otavio Balbino
#64212 Hi guys,
I am developing an application to turn on/off some devices through Firebase. It is working fine, but when i turn off my router, all of my ESP outputs goes to OFF. Is there a way to keep the previous values on I/O after the connection stop?
Here is my example code:

Code: Select all#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>


#define firebaseURL "xxxxxxx.firebaseio.com"
#define authCode "xxxxxxxxx"

#define wifiName "xxxxxx"
#define wifiPass "xxxxxxxx"
String chipID = "00001";

void setupWiFi(){

   WiFi.begin(wifiName, wifiPass);
   Serial.print("Connecting...");

   while(WiFi.status() != WL_CONNECTED){
      
       Serial.print(".");
       delay(100);
   }
   
   Serial.println("Connected with IP: ");
   Serial.println(WiFi.localIP());
}

void setupFirebase(){

   Firebase.begin(firebaseURL, authCode);
}

void getData(){

   String path = chipID + "/states";
   FirebaseObject object = Firebase.get(path);

   bool led0 = object.getBool("D0");

   bool led1 = object.getBool("D1");
 
   bool led2 = object.getBool("D2");

   /*Serial.println("LED0: ");
   Serial.println(led0);
   Serial.println("\t");

   Serial.println("LED1: ");
   Serial.println(led1);
   Serial.println("\t");

   Serial.println("LED2: ");
   Serial.println(led2);
   Serial.println("\t");*/

  digitalWrite(D0,led0);
  digitalWrite(D1,led1);
  digitalWrite(D2,led2);
}


void setup()
{
   pinMode(D0, OUTPUT);
   pinMode(D1, OUTPUT);
   pinMode(D2, OUTPUT);

   Serial.begin(9600);
   setupWiFi();
   setupFirebase();
   
}

void loop()
{

  getData();

  if(WiFi.status() != WL_CONNECTED){

     Serial.println("Disconnected...");
  }else{

    Serial.println("Connected...");
    delay(1000);
  }
 
 
}