#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "https://raw.githubusercontent.com/erichuang2013/erichuang2013.github.io/master/b.txt";
#define led_pin 13
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
pinMode(led_pin, OUTPUT);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("OK! IP=");
Serial.println(WiFi.localIP());
// digitalWrite(led_pin, HIGH);
Serial.print("Fetching " + url + "... ");
// HTTPClient http;
// http.begin(url);
// int httpResponseCode = http.GET();
// if (httpResponseCode > 0) {
// Serial.print("HTTP ");
// Serial.println(httpResponseCode);
// String payload = http.getString();
// Serial.println();
// Serial.println(payload);
// }
// else {
// Serial.print("Error code: ");
// Serial.println(httpResponseCode);
// Serial.println(":-(");
// }
}
void loop() {
HTTPClient http;
http.begin(url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println();
Serial.println(payload);
if (payload.toInt() == 0) {
digitalWrite(led_pin, HIGH);
} else {digitalWrite(led_pin, LOW);}
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
delay(5000);
}