SETTING UP FIRESTORE CODE
Closed this issue · 6 comments
Hello,
I have been working with ESP32 and Firestore for a while. Currently I'm making a home automation app with flutter, firestore and ESP32. I came across your library a few hours ago, and I have some question and problems that I will need some help.
If I set up a security rules, will your code be able to authenticate the read, write, update, delete of data?
I'm currently trying to set up with my firestore, this is what I'm attempting:
#include <firestore_config.h>
#include <firestore.h>
#include <WiFi.h>
// Definindo WiFi
#define WIFI_SSID "inte"
#define WIFI_PASSWORD "pass"
void setup() {
Serial.begin(115200);
firestore_init();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Conectando ao WiFi...");
while (WiFi.status() != WL_CONNECTED)
{
Serial.println(".");
delay(500);
}
Serial.println("Conectado ao WiFi");
}
void loop() {
get_collection();
delay(2000);
}
void get_collection(void)
{
char *pcCollection;
uint32_t u32CollectionLen;
if(FIRESTORE_OK == firestore_get_collection("dadosusuarios", &pcCollection, &u32CollectionLen))
{
ESP_LOGI(TAG, "Collection length: %d", u32CollectionLen);
ESP_LOGI(TAG, "Collection content:\r\n%.*s", u32CollectionLen, pcCollection);
}
else
{
ESP_LOGE(TAG, "Couldn't get collection");
}
}
I'm getting a error for firebaseConfig, I get:
sketch_jan26b:8:7: error: 'firebaseConfig' does not name a type
const firebaseConfig = {
^
/var/folders/05/spv322w148v8nv75jdgv13th0000gn/T/arduino_modified_sketch_463505/sketch_jan26b.ino: In function 'void loop()':
sketch_jan26b:39:3: error: a function-definition is not allowed here before '{' token
{
^
sketch_jan26b:56:1: error: expected '}' at end of input
}
This is my database image
If I want to access sub collection how would I be able to do so?
Hope your library have success,
Regards Niltonsf
Hello, thanks for your interest in this library. There are a couple of things that I need to clarify here:
First: this library is developed to be used as an ESP-IDF component and it is not tested with the Arduino framework.
Second: You have some errors in your code like defining a function inside a function (get_collection inside loop)
another thing: the const firebaseConfig is a javascript snippet shown in readme to explain where you can find the api key, you don't need to put it in your code
@kaizoku-oh Hey, Oh sorry I have made that mistake of adding the API_KEY and the PROJECT_ID in the file. I have updated the firestore_config.h with my PROJECT_ID and API_KEY. I will update the question with what I currently have. But I got an error when uploading the code:
/Users/niltonsf/Documents/Arduino/libraries/firestore-main/firestore.c: In function 'firestore_init':
/Users/niltonsf/Documents/Arduino/libraries/firestore-main/firestore.c:32:21: error: 'esp_http_client_config_t {aka struct <anonymous>}' has no member named 'buffer_size_tx'
stCtx.stHttpconfig.buffer_size_tx = FIRESTORE_HTTP_INTERNAL_TX_BUF_SIZE;
^
/Users/niltonsf/Documents/Arduino/libraries/firestore-main/firestore.c: In function '_firestore_http_event_handler':
/Users/niltonsf/Documents/Arduino/libraries/firestore-main/firestore.c:350:8: error: 'HTTP_EVENT_HEADERS_SENT' undeclared (first use in this function)
case HTTP_EVENT_HEADERS_SENT:
^
As I said I haven't tested this on arduino framework but you may need the esp_http_client component because it's a dependency for firestore component
Oh, The framework you have used is ESP-IDP? Is coding close to Arduino framework?
You can find everything on using the component in the example folder
and here you'll find how to setup your environment https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/
I'm going to close the issue, if have any other questions feel free reopen it.