diff --git a/esp32-timed-switch.ino b/esp32-timed-switch.ino index d5f9339..890e873 100644 --- a/esp32-timed-switch.ino +++ b/esp32-timed-switch.ino @@ -13,19 +13,14 @@ // -------------------------------------------- -const char* html_app="ESP32 timed Switch

Scheduler

"; - - -// PREFERENCES +// PREFRENCES Preferences preferences; #define RW_MODE false #define RO_MODE true // WIFI -// const char* ssid = "/tmp/lab"; -// const char* password = "bitte2cucung"; -const char* ssid = "Wokwi-GUEST"; -const char* password = ""; +const char* ssid = "/tmp/lab"; +const char* password = "bitte2cucung"; const uint8_t wifi_loop_max = 10; // NTP @@ -70,7 +65,7 @@ unsigned int pin_list[2] = { }; // HTTP -WiFiClient client; +WiFiClient http_client; WiFiServer http_server(3000); String request; @@ -193,7 +188,7 @@ void run_scheduler(){ // HTTP -void deserializeSchedule(WiFiClient &client, int schedule[24]) { +void deserializeSchedule(String content, int schedule[24]) { client.readBytes((char*)schedule, 24 * sizeof(int)); } @@ -274,6 +269,18 @@ void setup(){ } +void html() { + http_client.println("HTTP/1.1 200 OK"); + http_client.println("Content-Type: text/html"); + http_client.println("Connection: close"); + http_client.println(); + + http_client.println(""); + http_client.println(""); + http_client.println(""); + http_client.println(""); + +} void loop(){ @@ -283,8 +290,8 @@ void loop(){ } - client = http_server.available(); - if (!client) { + http_client = http_server.available(); + if (!http_client) { return; } @@ -311,13 +318,6 @@ void loop(){ client.println("Connection: close"); client.println(); } - // GET homepage - } else if (request.indexOf("GET /") >= 0) { - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: text/plain"); - client.println("Connection: close"); - client.println(); - client.println(html_app); } // POST request @@ -337,21 +337,15 @@ void loop(){ // Update the schedule for the specified plug if (plugId >= 0 && plugId < 8) { - // deserializeSchedule(&client, scheduler_list[plugId]); + deserializeSchedule(postBody, scheduler_list[plugId]); Serial.println("Schedule updated for plug " + plugIdStr); } else { Serial.println("Invalid plug ID"); } - } - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: text/plain"); - client.println("Connection: close"); - client.println(); - client.println(html_app); - client.stop(); + http_client.stop(); } diff --git a/html/index.html b/html/index.html index 9b13b2e..589503b 100644 --- a/html/index.html +++ b/html/index.html @@ -234,19 +234,18 @@ app.component('plugScheduleWidget', {