无法从NodeMCU中的Firebase读取数据

时间:2019-01-29 16:34:36

标签: firebase arduino google-cloud-platform iot esp8266

我正在尝试使用nodemcu在firebase中读写数据;一切都在开始时起作用,但是在运行几分钟后,每次都会执行firebase.failed()循环。但是firebase.error()没有显示特定错误。我该怎么办?

代码如下:

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <WiFiUdp.h>
WiFiUDP Udp;

#define FIREBASE_HOST "mystique12.firebaseio.com"   
#define FIREBASE_AUTH "L5XkMKQkof54yoKnOJLk7mP2LHo3vTZILwZ947rO"                                    
#define wifiled D3
#define LED D5
#define button D6
float val;
int touch=0;

const char* ssid = "Redmi 3s";
const char* password = "alohomora";


void setup() 
{
  Serial.begin(115200);                                                  
  pinMode(LED,OUTPUT);
  pinMode(wifiled,OUTPUT);
  pinMode(button,INPUT);
  digitalWrite(LED,LOW);


   WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
   digitalWrite(wifiled, HIGH); 
   delay(500);              
   digitalWrite(wifiled, LOW);    
   delay(500);
   Serial.print("."); 
  }
  Serial.println(" connected");
  digitalWrite(wifiled, HIGH); 


  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.set("S1",0);                     

}

void loop() 
{
   if(digitalRead(button)==HIGH){     
      touch+=1;
      if(touch==1){Firebase.setFloat("S1",2); }
 else if(touch==2){Firebase.setFloat("S1",3); }
 else if(touch==3){Firebase.setFloat("S1",1); }
 else if(touch==4){Firebase.setFloat("S1",0);  touch=0;}     
 }

  val=Firebase.getFloat("S1");   
  Serial.println(val); 
    if (Firebase.failed()) {                  
  Serial.print("getting/val failed:");   
  Serial.print(Firebase.error());        
  }
  delay(1000);                                 
       if(val==0){analogWrite(LED,0);   }
  else if(val==1){analogWrite(LED,255); }
  else if(val==2){analogWrite(LED,25);  }
  else if(val==3){analogWrite(LED,125); }                                  
}

enter image description here

0 个答案:

没有答案