#include #include // Wi-Fi credentials const char* ssid = "open_wrt_inf"; const char* password = "c@psl0ck316"; // Pin configuration const int pinD5 = D5; void setup() { // Initialize serial communication Serial.begin(115200); delay(10); // Configure pinD5 as input pinMode(pinD5, INPUT); // Connect to Wi-Fi WiFi.begin(ssid, password); Serial.print("Connecting to "); Serial.print(ssid); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } String followRedirects(String url) { WiFiClient client; HTTPClient http; http.begin(client, url); int httpCode = http.GET(); String payload = ""; if (httpCode > 0) { Serial.printf("[HTTP] GET... code: %d\n", httpCode); if (httpCode == HTTP_CODE_OK) { payload = http.getString(); } else if (httpCode == HTTP_CODE_MOVED_PERMANENTLY || httpCode == HTTP_CODE_FOUND) { String newUrl = http.getLocation(); Serial.print("Redirected to: "); Serial.println(newUrl); payload = followRedirects(newUrl); // Recursively follow redirects } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); // Close connection return payload; } void loop() { // Read the state of pinD5 bool state = digitalRead(pinD5); Serial.println(state); // Prepare URL based on the state of pinD5 String url = "http://www.calandapp.org/bla.php?"; if (state == 1) { url += "high"; } else { url += "low"; } Serial.print(url); // Check WiFi connection status if (WiFi.status() == WL_CONNECTED) { String payload = followRedirects(url); Serial.println(payload); } // Wait for 1 second delay(2000); }