#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
// Replace with your network credentials
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"
// Replace with your Firebase project settings
#define API_KEY "your_firebase_web_api_key"
#define DATABASE_URL "your-project-id.firebaseio.com" // without https://
// Firebase objects
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(500);
}
Serial.println(" connected.");
// Assign Firebase credentials
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
// Anonymous sign-in (leave email/password blank)
auth.user.email = "";
auth.user.password = "";
// Start Firebase
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
// Wait for sign-in to complete
while (!Firebase.ready()) {
Serial.println("Waiting for Firebase to be ready...");
delay(1000);
}
Serial.println("Firebase is ready!");
Serial.println("UID: " + auth.token.uid);
// Push test data
if (Firebase.setString(fbdo, "/test_path/message", "Gas Sensor Ready")) {
Serial.println("Data sent to Firebase!");
} else {
Serial.println("Failed to send: " + fbdo.errorReason());
}
}
void loop() {
// optional: send data repeatedly
}
I have give correct api key and url
FAILED REASON: missing required credentials e.g., database URL, host . error