esp32 和 firestore 之间的通信“响应负载读取超时”

问题描述 投票:0回答:0

我正在尝试使用 ESP32 和 DS18B20 温度传感器将温度传感器数据上传到 firestore 数据库中。问题是当尝试将 ESP32 连接到 firestore 数据库时 我不知道这个问题的原因是什么,代码编译并上传成功,在串行监视器中打印了这个

Connecting to WiFi....

Connected with IP: 192.168.

firebase client v4.4.10 Token info: type = id token (GITKit token),
status = on request Token info: type = id token (GITKit token), status
= error Token error: code: -6, message: response payload read timed out
        Token info: type = id token (GITKit token), status = on
request Token info: type = id token (GITKit token), status = error
Token error: code: -6, message: response payload read timed out       
Token info: type = id token (GITKit token), status = on request Token
info: type = id token (GITKit token), status = error Token error:
code: -6, message: response payload read timed out        Token info:
type = id token (GITKit token), status = on request Token info: type =
id token (GITKit token), status = error Token error: code: -6,
message: response payload read timed out

如果有帮助的话,这是代码

#include <Arduino.h>
#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>

#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <addons/TokenHelper.h>

#define WIFI_SSID "TPlink"
#define WIFI_PASSWORD "laugh__ta1e"

#define API_KEY "the firestore API key"
#define FIRESTORE_PROJECT_ID "firestore project ID"
#define USER_EMAIL "email"
#define USER_PASSWORD "password"

int oneWireBus = 4;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);

FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

void setup()
{
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to WiFi");

  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }

  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Serial.printf("firebase client v%s\n\n", FIREBASE_CLIENT_VERSION);

  config.api_key = API_KEY;

  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  config.token_status_callback = tokenStatusCallback;
  Firebase.reconnectNetwork(true);

  Firebase.reconnectWiFi(true);

  Firebase.begin(&config, &auth);
  delay(1500);
  Serial.println("Connected successfully");

  // Start the DS18B20 sensor
  sensors.begin();
  pinMode(btn, INPUT_PULLUP);
}

void loop()
{
  String path = "/Sensor/temp";
  FirebaseJson content;
  float tempC = sensors.getTempCByIndex(0);

  content.set("TempCollection/Device1/Temperature", String(tempC));
  Serial.print("update/add temp to data... ");

  if (Firebase.Firestore.patchDocument(&fbdo, FIRESTORE_PROJECT_ID, "", path.c_str(), content.raw(), "Temperature"))
  {
    Serial.printf("ok\n%s\n\n", fbdo.payload().c_str());
  }
  else
  {
    Serial.println("its in here !!!");
    Serial.println(fbdo.errorReason());
  }
}

我不知道这是否相关,但在创建 firestore 数据库时我一开始无法错误消息 为此,我禁用了反应扩展并取消选择“在控制台中显示 CORS 错误”,我刷新并创建了数据库

我尝试更改安全规则 我尝试更改 firebase 中的注册方法 至于代码我不知道要改变什么

经过进一步测试,问题可能就在这里

#include <addons/TokenHelper.h>

FirebaseConfig 配置; config.token_status_callback = tokenStatusCallback;

firebase google-cloud-firestore arduino esp32 platformio
© www.soinside.com 2019 - 2024. All rights reserved.