0

I have an ESP8266 receiving a stream from a firebase value. The value determines the state of an LED output D0. The stream works for the first few minutes after hard reset but Firebase.failed() returns true thereafter. The function of the pushbutton 4 in the code is to manually flash the LED D0. My code is based on this example.

My ESP board

My database:

enter image description here

My serial terminal:

enter image description here

My code:

#include <ESP8266WiFi.h>                                                // esp8266 library
#include <FirebaseArduino.h>                                             // firebase library

//#include <WiFiClientSecure.h>

#define WIFI_SSID "D*******5"
#define WIFI_PASSWORD "08*******7"

#define FIREBASE_HOST "esp2866-02.firebaseio.com"             // the project name address from firebase id
#define FIREBASE_AUTH "UR3***********************VnK7"       // the secret key generated from firebase




String eventString = "";                                                     // 
int prevSet = 0;
int led = D0;                                                                // for external led
int btn = 4;                                                                // for push button circuit 

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status



void setup() {
  Serial.begin(9600);
  delay(1000);    
  pinMode(led, OUTPUT); 
  pinMode(btn, INPUT);                
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                                      //try to connect with wifi
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  //Flashes led to indicate connect est: 
  digitalWrite(led, HIGH); 
  delay(200);    
  digitalWrite(led, LOW); 

  Serial.println();
  Serial.print("Connected to ");
  Serial.println(WIFI_SSID);
  //print local IP address
  Serial.print("IP Address is : ");
  Serial.println(WiFi.localIP());                                                      
  // connect to firebase
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  //send initial string of led status
  Firebase.setString("LED_STATUS", "OFF");                                          
  delay(1000); 
  Firebase.stream("LED_STATUS"); 
}

void loop() {
  if (Firebase.failed()) {
    Serial.println("streaming error");
    Serial.println(Firebase.error());
    //warning flash
    digitalWrite(led, HIGH);
    delay(200);    
    digitalWrite(led, LOW); 
    delay(1000);  
  }
  // read the state of the pushbutton value:
  buttonState = digitalRead(btn);
  if( buttonState == 1 ){

      digitalWrite(led, HIGH);
      delay(1000);    
      digitalWrite(led, LOW); 
  }

   if (Firebase.available()) {
     FirebaseObject event = Firebase.readEvent();
     String eventType = event.getString("type");
     eventType.toLowerCase();

     if (eventType == "put") {
       Serial.print("data: ");
       eventString = event.getString("data");
       Serial.println(eventString);

       if(eventString == "BLNK"){
         digitalWrite(led, HIGH);
         delay(1000);    
         digitalWrite(led, LOW); 
         Firebase.setString("LED_STATUS", "OFF");  
       }


     }
  } 

 delay(30);  
}

I've updated the libraries. How do I prevent this error or at the very least how do I obtain more information resulting in the error?

  • maybe they block you because of too many requests in a short time – Juraj Jun 6 at 13:53
  • How do I limit or delay the requests. In the loop? – Brandon Pillay Jun 6 at 13:55
  • That worked thanks! – Brandon Pillay Jun 6 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.