#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* serverName = "https://883b16175593.ngrok-free.app/esp32_web/get_state.php";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nā
WiFi connected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure(); // Abaikan sertifikat SSL (penting di Wokwi)
HTTPClient https;
https.begin(client, serverName);
int httpResponseCode = https.GET();
if (httpResponseCode > 0) {
String payload = https.getString();
Serial.print("š„ Server Response: ");
Serial.println(payload);
} else {
Serial.print("ā Error code: ");
Serial.println(httpResponseCode);
}
https.end();
} else {
Serial.println("ā WiFi Disconnected!");
}
delay(5000); // cek server tiap 5 detik
}