/* ESP32 WiFi STA Mode http:://www.electronicwings.com */ #include #include #include #include "esp_system.h" // For example purpose String formattedDate; // Define NTP Client to get time WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); // Timer conf const int wdtTimeout = 30; //time in ms to trigger the watchdog hw_timer_t *timer = NULL; // Wifi conf const char* ssid = "Wokwi-GUEST"; /*Enter Your SSID*/ const char* password = ""; /*Enter Your Password*/ WiFiServer server(80); /* Instance of WiFiServer with port number 80 */ String request; bool L1 = false; bool L2 = false; bool L3 = false; bool L4 = false; bool L5 = false; bool L6 = false; bool L7 = false; bool L8 = false; String programme = "000000000000000000"; WiFiClient client; void callback() { Serial.print("Callback... "); } void setup() { Serial.begin(9600); Serial.print("Connecting to: "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(100); } Serial.print("\n"); Serial.print("Connected to Wi-Fi "); Serial.println(WiFi.SSID()); delay(1000); server.begin(); /* Start the HTTP web Server */ Serial.print("Connect to IP Address: "); Serial.print("http://"); Serial.println(WiFi.localIP()); timeClient.begin(); // Set offset time in seconds to adjust for your timezone, for example: timeClient.setTimeOffset(7200); timeClient.update(); timer = timerBegin(0, 80, true); //timer 0, div 80 timerAttachInterrupt(timer, &callback, true); //attach callback timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us timerAlarmEnable(timer); //enable interrupt } void html() { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("

Programmation actuelle

"); client.println("

"+programme+"

"); client.print("
"); client.print(""); client.print("
"); client.println("

Prises Programmées

"); if (L1) { client.print("

"); } else { client.print("

"); } if (L2) { client.print("

"); } else { client.print("

"); } if (L3) { client.print("

"); } else { client.print("

"); } if (L4) { client.print("

"); } else { client.print("

"); } if (L5) { client.print("

"); } else { client.print("

"); } if (L6) { client.print("

"); } else { client.print("

"); } if (L7) { client.print("

"); } else { client.print("

"); } if (L8) { client.print("

"); } else { client.print("

"); } client.println(""); client.println(""); } void loop() { formattedDate = timeClient.getFormattedTime(); Serial.println(formattedDate); timerWrite(timer, 0); //reset timer (feed watchdog) long loopTime = millis(); /* // Extract date int splitT = formattedDate.indexOf("T"); dayStamp = formattedDate.substring(0, splitT); Serial.print("DATE: "); Serial.println(dayStamp); // Extract time timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1); Serial.print("HOUR: "); Serial.println(timeStamp); */ delay(1000); /* client = server.available(); if (!client) { return; } while (client.connected()) { if (client.available()) { char c = client.read(); request += c; if (c == '\n') { String postres = client.readString(); int indp = postres.indexOf("progo=")+6; Serial.println(postres); Serial.println(request); if (request.indexOf("POST /PROG") != -1) { Serial.println("go"); programme =postres.substring(indp); } if (request.indexOf("GET /L1") != -1) { L1 = !L1; } if (request.indexOf("GET /L2") != -1) { L2 = !L2; } if (request.indexOf("GET /L3") != -1) { L3 = !L3; } if (request.indexOf("GET /L4") != -1) { L4 = !L4; } if (request.indexOf("GET /L5") != -1) { L5 = !L5; } if (request.indexOf("GET /L6") != -1) { L6 = !L6; } if (request.indexOf("GET /L7") != -1) { L7 = !L7; } if (request.indexOf("GET /L8") != -1) { L8 = !L8; } html(); break; } } } delay(1); request = ""; client.stop(); */ }