#include <Arduino.h>
#include <WiFi.h>
#include <FirebaseESP32.h>

// Define the Firebase Data object
FirebaseData fbdo;

/* 1. Define the WiFi credentials */
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""

// For the following credentials, see examples/Authentications/SignInAsUser/EmailPassword/EmailPassword.ino

/* 2. Define the API Key */
#define API_KEY "AIzaSyBqDekwuU37xWFpQXrhEl7fss-nucK73qg"

/* 3. Define the project ID */
#define FIREBASE_PROJECT_ID "earthquake-41704"

/* 4. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "[email protected]"
#define USER_PASSWORD "123456"

// Define the FirebaseAuth data for authentication data
FirebaseAuth auth;

// Define the FirebaseConfig data for config data
FirebaseConfig config;



unsigned long dataMillis = 0;
int count = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32 is working!");

  pinMode(13, OUTPUT);

  // Start WiFi Connection
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to Wi-Fi");
  unsigned long ms = millis();
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  // Firebase Connection
  Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
  /* Assign the api key (required) */
  config.api_key = API_KEY;

  /* Assign the user sign in credentials */
  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  /* Assign the RTDB URL */
  config.database_url = "https://earthquake-41704-default-rtdb.firebaseio.com";

  // Limit the size of response payload to be collected in FirebaseData
  // fbdo.setResponseSize(2048);

  Firebase.begin(&config, &auth);

  Firebase.reconnectWiFi(true);
}

void loop() {

  digitalWrite(13, HIGH);
  delay(1000); // this speeds up the simulation
  digitalWrite(13, LOW);
  delay(1000); // this speeds up the simulation
  Serial.printf("Firebase Client v%s\n\n", Firebase.setInt(fbdo, "/test/int", 0));
    delay(5000);
    }