From 42a1d3a7a58ed22f4fc1d82a22116fb9356c54db Mon Sep 17 00:00:00 2001 From: Pierre Tellier Date: Thu, 17 Apr 2025 09:31:19 +0200 Subject: [PATCH] feat: added wifi slider --- wifi/wifi.ino | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/wifi/wifi.ino b/wifi/wifi.ino index 203c6aa..f61f52b 100644 --- a/wifi/wifi.ino +++ b/wifi/wifi.ino @@ -13,8 +13,8 @@ #include // Replace with your network credentials -const char* ssid = "ESP32-ping-pong"; -const char* password = "REPLACE_WITH_YOUR_PASSWORD"; +const char* ssid = "ESP_ping"; +const char* password = "pong"; const char* PARAM_INPUT_1 = "output"; const char* PARAM_INPUT_2 = "state"; @@ -35,7 +35,7 @@ const char index_html[] PROGMEM = R"rawliteral( body {max-width: 600px; margin:0px auto; padding-bottom: 25px;} .switch {position: relative; display: inline-block; width: 120px; height: 68px} .switch input {display: none} - .slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 6px} + .slider {background-color: #ccc; border-radius: 6px} .slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 3px} input:checked+.slider {background-color: #b30000} input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)} @@ -44,12 +44,15 @@ const char index_html[] PROGMEM = R"rawliteral(

ESP Web Server

%BUTTONPLACEHOLDER% - @@ -60,34 +63,23 @@ String processor(const String& var){ //Serial.println(var); if(var == "BUTTONPLACEHOLDER"){ String buttons = ""; - buttons += "

Output - GPIO 2

"; - buttons += "

Output - GPIO 4

"; - buttons += "

Output - GPIO 33

"; + buttons += "
"; + buttons += "
"; + buttons += "
"; + buttons += "
"; + buttons += "
"; + + return buttons; } return String(); } -String outputState(int output){ - if(digitalRead(output)){ - return "checked"; - } - else { - return ""; - } -} void setup(){ // Serial port for debugging purposes Serial.begin(115200); - pinMode(2, OUTPUT); - digitalWrite(2, LOW); - pinMode(4, OUTPUT); - digitalWrite(4, LOW); - pinMode(33, OUTPUT); - digitalWrite(33, LOW); - Serial.print("Setting AP (Access Point)…"); WiFi.softAP(ssid); @@ -109,7 +101,7 @@ void setup(){ if (request->hasParam(PARAM_INPUT_1) && request->hasParam(PARAM_INPUT_2)) { inputMessage1 = request->getParam(PARAM_INPUT_1)->value(); inputMessage2 = request->getParam(PARAM_INPUT_2)->value(); - digitalWrite(inputMessage1.toInt(), inputMessage2.toInt()); + int requestedValue = inputMessage2.toInt(); } else { inputMessage1 = "No message sent";