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

// const char *ssid = "gta";
const char *ssid = "Wokwi-GUEST";
// const char *password = "gta123@";
const char *password = "";

const char *serverUrl = "https://api.thingspeak.com/update?api_key=VFEZS0RACY1RKYBH";

int field1Val = 70;
int field2Val = 80;
int field3Val = 90;
int field4Val = 0;
int field5Val = 1;


// https://api.thingspeak.com/update?api_key=VFEZS0RACY1RKYBH&field1=64&field2=100&field3=60&field4=1&field5=0

void setup() {
  Serial.begin(115200);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Make GET request
  makeGetRequest();
}

void makeGetRequest() {
  HTTPClient http;

  String url = String(serverUrl) +
               "&field1=" + field1Val +
               "&field2=" + field2Val +
               "&field3=" + field3Val +
               "&field4=" + field4Val +
               "&field5=" + field5Val;

  Serial.println("Sending GET request to: " + url);

  http.begin(url);

  int httpCode = http.GET();
  if (httpCode > 0) {
    Serial.printf("HTTP response code: %d\n", httpCode);
    String payload = http.getString();
    Serial.println("Server response: " + payload);
  } else {
    Serial.printf("HTTP request failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();
}

void loop() {
  // Your main code here
}