#include <WiFi.h>
#include <HTTPClient.h>
String URL_F = "https://s-m.com.sa/f.html";
String URL_B = "https://s-m.com.sa/b.html";
String URL_R = "https://s-m.com.sa/r.html";
String URL_L = "https://s-m.com.sa/l.html";
const char* ssid = "Wokwi-GUEST";
const char* pass = "";
const int LED_F = 32; // Forward LED
const int LED_B = 22; // Backward LED
const int LED_R = 25; // Right LED
const int LED_L = 33; // Left LED
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
pinMode(LED_F, OUTPUT);
pinMode(LED_B, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(LED_L, OUTPUT);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
getAndDisplayData(URL_F, LED_F, "forward");
getAndDisplayData(URL_B, LED_B, "backward");
getAndDisplayData(URL_R, LED_R, "right");
getAndDisplayData(URL_L, LED_L, "left");
} else {
Serial.println("WiFi Disconnected");
}
}
void getAndDisplayData(String url, int ledPin, String direction) {
HTTPClient http;
http.begin(url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String payload = http.getString();
Serial.println("Data for " + direction + ": " + payload);
// Turn on the LED for the current direction
digitalWrite(ledPin, HIGH);
// Turn off the LED for the other directions
if (ledPin != LED_F) {
digitalWrite(LED_F, LOW);
}
if (ledPin != LED_B) {
digitalWrite(LED_B, LOW);
}
if (ledPin != LED_R) {
digitalWrite(LED_R, LOW);
}
if (ledPin != LED_L) {
digitalWrite(LED_L, LOW);
}
} else {
// Turn off all LEDs
digitalWrite(LED_F, LOW);
digitalWrite(LED_B, LOW);
digitalWrite(LED_R, LOW);
digitalWrite(LED_L, LOW);
Serial.println("Failed to get data for " + direction);
}
http.end();
}