#include <WiFi.h>
#include <HTTPClient.h>
const int ledPin = 2;
const char* ssid = "Wokwi-GUEST"; // اسم الشبكة الوهمية
const char* password = ""; // كلمة المرور (فارغة)
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);
// الانتظار حتى الاتصال
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// إرسال طلب HTTP تجريبي
if(WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://worldtimeapi.org/api/timezone/Etc/UTC"); // موقع تجريبي يعطي الوقت
int httpCode = http.GET();
if(httpCode > 0) {
Serial.printf("HTTP Response code: %d\n", httpCode);
String payload = http.getString();
Serial.println("Response payload:");
Serial.println(payload);
} else {
Serial.printf("HTTP request failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
}
// void loop() {
// // لا شيء في الـ loop، مجرد مثال اتصال مرة واحدة
// }
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}