#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid="Wokwi-GUEST";
const char* password="";
const char* webhook_url="https://script.google.com/macros/s/AKfycbzkhM-MaUokCx_0XfaZIcW-VC6p7S9z6SrdVGO9bxWfpaP1TTeAJ84SMn6H_mHWPypE0g/exec";
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Enter access status (GRANTED or DENIED):");
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status()!= WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi!");
}
void loop() {
if (Serial.available()) {
String status = Serial.readStringUntil('\n');
status.trim();
if (status.length() > 0) {
sendToGoogleSheet(status);
}
}
}
void sendToGoogleSheet(String status) {
if (WiFi.status()== WL_CONNECTED) {
HTTPClient http;
http.begin(webhook_url);
http.addHeader("Content-Type", "application/json");
String jsonPayload = "{\"status\":\"" + status + "\"}";
int httpResponseCode = http.POST(jsonPayload);
if (httpResponseCode > 0) {
Serial.println("Logged to Google Sheet.");
} else {
Serial.print("Error logging to Google Sheet: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("WiFi not connected");
}
}