#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const int buttonPin = 17;
const int ledPin = 33;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
delay(10);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
// Button is pressed, make HTTP request
makeHttpRequest();
delay(1000); // debounce
}
}
void makeHttpRequest() {
HTTPClient http;
// Your Google Apps Script URL with the name parameter
String url = "https://script.google.com/macros/s/AKfycbxAEOzZ2BZnNl_l2c6rSodmUP0JrYaGC363kK86gzlX7G47U_2RUEaLpb8WyPJtC6jPyA/exec?name=Mustefa Sarbast";
Serial.print("Making HTTP request to: ");
Serial.println(url);
// Send the GET request
http.begin(url);
int httpResponseCode = http.GET();
// Check the response code
if (httpResponseCode == 200) {
Serial.println("HTTP request successful");
// Flash the LED three times
flashLed();
} else {
Serial.print("HTTP request failed. Response code: ");
Serial.println(httpResponseCode);
}
http.end();
}
void flashLed() {
for (int i = 0; i < 3; ++i) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}