Does anyone have a simple working ESP8266 to Firebase Firestore Code Template? I am trying to send data values from my Arduino Wemos D1 R2 ESP8266 to Firestore as my database, I am having trouble with the code since I can't find any sources for Firestore only for Realtime, I also have trouble to find which Library is the necessary, currently I have the library named: Firebase Arduino Client Library for ESP8266, ESP32 and RP2040 by mobizt as well as Firebase ESP8266 Client by mobizt. I can't seem to fix my code, since I don't know the structure to send data values to Firestore. What I want to happen is for the data values to be sent to my FIrestore, but before that the code will create a new document with a random document ID in my Firestore and then store those values. I hope someone can help me and give me tips, I just need a simple working code for the ESP8266 to send a value to Firestore and then I'll do the rest to modify it.
Here is a sample of my Code:
#include <Firebase_ESP_Client.h>
#include <WiFi.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "SSD"
#define WIFI_PASSWORD "Password"
/* 2. Define the API Key */
#define API_KEY "Web API Key"
/* 3. Define the project ID */
#define FIREBASE_PROJECT_ID "Project ID"
// Define Firebase Data object
FirebaseData fbdo;
// Define Firebase Firestore object
FirebaseFirestore firestore(&fbdo);
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
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);
// Initialize Firebase
Firebase.begin(FIREBASE_PROJECT_ID, API_KEY, WIFI_SSID, WIFI_PASSWORD);
}
void loop() {
// Create a FirebaseJson object and set the values
FirebaseJson content;
content.set("fields/pump/stringValue", "on");
// Build the Firestore document path
String path = "/esp/" + Firebase.auth().uid() + "/pump";
// Create the Firestore document
if (firestore.createDocument(path.c_str(), &content)) {
Serial.println("Document created successfully.");
} else {
Serial.println("Error creating document.");
Serial.println(firestore.errorReason());
}
delay(5000);
}