#include <WiFi.h>
#include <WiFiClient.h>
#include <HTTPClient.h>


#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
const char* firebaseHost = "esp8266-e1753-default-rtdb.firebaseio.com";
const char* firebaseKey = "AIzaSyDHUHCInzdvk814SPnQLLpXW5c1bYyZiyo";

// Defining the WiFi channel speeds up the connection:
#define WIFI_CHANNEL 6
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
  Serial.print("Connecting to WiFi ");
  Serial.print(WIFI_SSID);
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println(" Connected!");

  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  sendDataToFirebase("sensorValue", "123");
}

void sendDataToFirebase(const char* field, const char* value) {
  WiFiClient client;
  HTTPClient http;

  String url = "https://esp8266-e1753-default-rtdb.firebaseio.com/";

  http.begin(client, url);
  http.addHeader("Content-Type", "application/json");

  String payload = "{\"" + String(field) + "\":\"" + String(value) + "\"}";
  
  int httpResponseCode = http.POST(payload);

  if (httpResponseCode > 0) {
    Serial.printf("HTTP POST request sent to Firebase. Response code: %d\n", httpResponseCode);
  } else {
    Serial.printf("Error sending HTTP POST request to Firebase. Error code: %d\n", httpResponseCode);
  }

  http.end();
}


void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}
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