#include <WiFi.h>
#include <HTTPClient.h>
// Wokwi's free simulated Wi-Fi
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Your active Localtunnel URL with the webhook path attached
const char* serverName = "https://evil-clubs-grow.loca.lt/webhook/fault";
const int buttonPin = 13;
int lastButtonState = HIGH;
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
Serial.print("Connecting to simulated grid network");
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\n[SYSTEM ONLINE] Monitoring voltage thresholds.");
}
void loop() {
int currentButtonState = digitalRead(buttonPin);
// Trigger on button press (simulated voltage drop)
if (currentButtonState == LOW && lastButtonState == HIGH) {
Serial.println("\n[CRITICAL] Voltage anomaly detected!");
Serial.println("Firing L2 escalation webhook...");
if(WiFi.status() == WL_CONNECTED){
HTTPClient http;
http.begin(serverName);
// Force the connection to wait up to 10 seconds to bypass network lag
http.setTimeout(10000);
// Essential headers for JSON and bypassing Localtunnel's proxies
http.addHeader("Content-Type", "application/json");
http.addHeader("Bypass-Tunnel-Reminder", "true");
http.addHeader("User-Agent", "ESP32-VoltGuard");
// Fire the POST request
int httpResponseCode = http.POST("{\"fault_code\":\"V-DROP-7.8kW\"}");
if (httpResponseCode > 0) {
Serial.print("Webhook delivered. Server response code: ");
Serial.println(httpResponseCode);
} else {
Serial.print("Error sending webhook: ");
Serial.println(http.errorToString(httpResponseCode).c_str());
}
http.end();
}
// 10-second delay to prevent spamming the API
delay(10000);
}
lastButtonState = currentButtonState;
delay(50); // Simple debounce
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4