Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

c++ - ESP32 with Rest Api in Cloud Firestore

I'm working with ESP32 with Cloud Firestore. I'm attempting to make a request to get the data from a certain collection and document.
I have been able to access a single collection but, I'm having problems accessing a subcollection.
This is my ESP32 code to get the collection data:

#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <WiFi.h>

#define lamp 13

const char* ssid = "SSID";
const char* password = "Ok";

void setup() {
  Serial.begin(115200);

  pinMode(lamp, OUTPUT);

  WiFi.begin(ssid, password);

  delay(5000);
  
  Serial.println("Connecting to WiFi");
  while (WiFi.status() != WL_CONNECTED){
    delay(1000);
    Serial.print(".");
  }
}

void loop() {
  if (WiFi.status() == WL_CONNECTED){
    
    HTTPClient http;
    
    http.begin("stuff.net/app/api/read/5j5UF0lFovW8g5QSXXymWYsz0QB2");
   
    int httpCode = http.GET();

    if (httpCode > 0){
      String payload = http.getString();          //ISSO é PARA GET REQUEST
      Serial.println(httpCode);
      Serial.println(payload);

      char json[500];
      payload.toCharArray(json, 500);
      StaticJsonDocument<1024> doc;
      deserializeJson(doc, json);

      String device0 = doc["device0"];
    }
    
    http.end();  
  }else{
    Serial.println("Erro com conex?o, chekar conex?o ao WiFi");
  }

  delay(1000);

}

This is how my Firestore looks: enter image description here

I have attempted:

https://stuff.net/app/api/read/5j5UF0lFovW8g5QSXXymWYsz0QB2/buttons/button0

Won't work

question from:https://stackoverflow.com/questions/65905624/esp32-with-rest-api-in-cloud-firestore

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...