简体   繁体   English

ESP8266 无法从 Google Firebase 读取数据

[英]ESP8266 unable to read data from Google Firebase

I'm trying to make an IOT app.我正在尝试制作一个物联网应用程序。 My android side is working good so far, however my ESP8266 is unable to read data from Firebase Database.到目前为止,我的 android 端运行良好,但是我的 ESP8266 无法从 Firebase 数据库读取数据。 There is no error while connecting to the internet using onboard ESP8266 though.使用板载 ESP8266 连接到互联网时没有错误。 Can anyone point to a possible error?谁能指出一个可能的错误? Thank You谢谢你

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define WIFI_SSID "WiFi"
#define WIFI_PASSWORD "xxxxxxxx"
#define FIREBASE_HOST "https://iot.firebaseio.com"
#define FIREBASE_AUTH "xxxxxxxx"
int LED1 = D5;
void setup()
{
Serial.begin(115200);
  pinMode(LED1, OUTPUT);
  Serial.println('\n');
  wifiConnect();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  delay(10);
}
void loop()
{  
  if(WiFi.status() != WL_CONNECTED)
  {
    wifiConnect();
  }
  delay(10);
  Serial.print("Data from firebase:" + Firebase.getString("LED1") + "\n");
  digitalWrite(LED1, Firebase.getString("LED1").toInt());
  //digitalWrite(LED1, HIGH);
  delay(10);
}
void wifiConnect()
{
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID); Serial.println(" ...");

  int teller = 0;
  while (WiFi.status() != WL_CONNECTED)
  {                                       // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++teller); Serial.print(' ');
  }

  Serial.println('\n');
  Serial.println("Connection established!");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
}

For anyone encountering this issue.对于遇到此问题的任何人。 I got it working by removing the forward slash '/' at the end and the https:// from the start of Host Address.我通过删除末尾的正斜杠“/”和主机地址开头的 https:// 来使其工作。

At the line:在线:

#define FIREBASE_HOST "https://iot.firebaseio.com"

you should fix to:你应该修复:

#define FIREBASE_HOST "iot.firebaseio.com"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM