#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 "dani@gmail.com"
#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);
    }
    

esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
led1:A
led1:C
r1:1
r1:2