From 2274c7ce4be4f868b8c28a5e8987e21261e5fba8 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 9 Nov 2023 21:34:43 +0100 Subject: [PATCH 1/2] fix: html page colors --- html/index.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/html/index.html b/html/index.html index 589503b..9b13b2e 100644 --- a/html/index.html +++ b/html/index.html @@ -234,18 +234,19 @@ app.component('plugScheduleWidget', { "; + + +// PREFERENCES Preferences preferences; #define RW_MODE false #define RO_MODE true // WIFI -const char* ssid = "/tmp/lab"; -const char* password = "bitte2cucung"; +// const char* ssid = "/tmp/lab"; +// const char* password = "bitte2cucung"; +const char* ssid = "Wokwi-GUEST"; +const char* password = ""; const uint8_t wifi_loop_max = 10; // NTP @@ -65,7 +70,7 @@ unsigned int pin_list[2] = { }; // HTTP -WiFiClient http_client; +WiFiClient client; WiFiServer http_server(3000); String request; @@ -188,7 +193,7 @@ void run_scheduler(){ // HTTP -void deserializeSchedule(String content, int schedule[24]) { +void deserializeSchedule(WiFiClient &client, int schedule[24]) { client.readBytes((char*)schedule, 24 * sizeof(int)); } @@ -269,18 +274,6 @@ 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(){ @@ -290,8 +283,8 @@ void loop(){ } - http_client = http_server.available(); - if (!http_client) { + client = http_server.available(); + if (!client) { return; } @@ -318,6 +311,13 @@ 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,15 +337,21 @@ void loop(){ // Update the schedule for the specified plug if (plugId >= 0 && plugId < 8) { - deserializeSchedule(postBody, scheduler_list[plugId]); + // deserializeSchedule(&client, 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); - http_client.stop(); + client.stop(); }