Components and supplies
Jumper wires (generic)
USB-A to Mini-USB Cable
ESP32 Wroom
LED (generic)
Solderless Breadboard Half Size
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
The code
arduino
Just copy and paste in Arduino IDE
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o */ 3 4 #include <WiFi.h> 5 6 const char* ssid = "user id"; 7 const char* password = "password"; 8 9 WiFiServer server(80); 10 11 String header; 12 String output26State = "off"; 13 String output27State = "off"; 14 15 const int output26 = 26; 16 const int output27 = 27; 17 18 void setup() { 19 Serial.begin(115200); 20 pinMode(output26, OUTPUT); 21 digitalWrite(output26, LOW); 22 digitalWrite(output27, LOW); 23 24 Serial.print("Connecting to "); 25 Serial.println(ssid); 26 WiFi.begin(ssid, password); 27 while (WiFi.status() != WL_CONNECTED) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println(""); 32 Serial.println("WiFi connected."); 33 Serial.println("IP address: "); 34 Serial.println(WiFi.localIP()); 35 server.begin(); 36 } 37 38 void loop(){ 39 WiFiClient client = server.available(); 40 if (client) { 41 Serial.println("New Client."); 42 String currentLine = ""; 43 while (client.connected()) { 44 if (client.available()) { 45 char c = client.read(); 46 Serial.write(c); 47 header += c; 48 if (c == '\ 49') { 50 if (currentLine.length() == 0) { 51 client.println("HTTP/1.1 200 OK"); 52 client.println("Content-type:text/html"); 53 client.println("Connection: close"); 54 client.println(); 55 56 // turns the GPIOs on and off 57 if (header.indexOf("GET /26/on") >= 0) { 58 Serial.println("GPIO 26 on"); 59 output26State = "on"; 60 digitalWrite(output26, HIGH); 61 } else if (header.indexOf("GET /26/off") >= 0) { 62 Serial.println("GPIO 26 off"); 63 output26State = "off"; 64 digitalWrite(output26, LOW); 65 } else if (header.indexOf("GET /27/on") >= 0) { 66 Serial.println("GPIO 27 on"); 67 output27State = "on"; 68 digitalWrite(output27, HIGH); 69 } else if (header.indexOf("GET /27/off") >= 0) { 70 Serial.println("GPIO 27 off"); 71 output27State = "off"; 72 digitalWrite(output27, LOW); 73 } 74 client.println("<!DOCTYPE html><html>"); 75 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\">"); 76 client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); 77 client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 78 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); 79 client.println(".button2 {background-color: #555555;}</style></head>"); 80 81 client.println("<body><h1>ESP32 Web Server</h1>"); 82 client.println("<p>GPIO 26 - State " + output26State + "</p>"); 83client.println(); 84 break; 85 } else { currentLine = ""; } 86 } else if (c != '\ ') { currentLine += c; } 87 } 88 89 } 90 header = ""; 91 client.stop(); 92 Serial.println("Client disconnected."); 93 Serial.println(""); 94 } 95 }
the code
arduino
1/********* 2made by Kusnh13 3For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o 4*********/ 5 6// Load Wi-Fi library 7 8 9#include <WiFi.h> 10 11// Replace with your network credentials 12const char* ssid = "CG4-1102"; 13const char* password = "py79iq0h"; 14 15// Set web server port number to 80 16WiFiServer server(80); 17 18// Variable to store the HTTP request 19String header; 20 21// Auxiliar variables to store the current output state 22String output26State = "off"; 23String output27State = "off"; 24 25// Assign output variables to GPIO pins 26const int output26 = 26; 27const int output27 = 27; 28 29void setup() { 30 Serial.begin(115200); 31 // Initialize the output variables as outputs 32 pinMode(output26, OUTPUT); 33 pinMode(output27, OUTPUT); 34 // Set outputs to LOW 35 digitalWrite(output26, LOW); 36 digitalWrite(output27, LOW); 37 38 // Connect to Wi-Fi network with SSID and password 39 Serial.print("Connecting to "); 40 Serial.println(ssid); 41 WiFi.begin(ssid, password); 42 while (WiFi.status() != WL_CONNECTED) { 43 delay(500); 44 Serial.print("."); 45 } 46 // Print local IP address and start web server 47 Serial.println(""); 48 Serial.println("WiFi connected."); 49 Serial.println("IP address: "); 50 Serial.println(WiFi.localIP()); 51 server.begin(); 52} 53 54void loop(){ 55 WiFiClient client = server.available(); // Listen for incoming clients 56 57 if (client) { // If a new client connects, 58 Serial.println("New Client."); // print a message out in the serial port 59 String currentLine = ""; // make a String to hold incoming data from the client 60 while (client.connected()) { // loop while the client's connected 61 if (client.available()) { // if there's bytes to read from the 26 - State " + output26State + "</p>"); 62 // If the output26State is off, it displays the ON button 63 if (output26State=="off") { 64 client.println("<p><a href=\\"/26/on\\"><button class=\\"button\\">ON</button></a></p>"); 65 } else { 66 client.println("<p><a href=\\"/26/off\\"><button class=\\"button button2\\">OFF</button></a></p>"); 67 } 68 69 // Display current state, and ON/OFF buttons for GPIO 27 70 client.println("<p>GPIO 27 - State " + output27State + "</p>"); 71 // If the output27State is off, it displays the ON button 72 if (output27State=="off") { 73 client.println("<p><a href=\\"/27/on\\"><button class=\\"button\\">ON</button></a></p>"); 74 } else { 75 client.println("<p><a href=\\"/27/off\\"><button class=\\"button button2\\">OFF</button></a></p>"); 76 } 77 client.println("</body></html>"); 78 79 // The HTTP response ends with another blank line 80 client.println(); 81 // Break out of the while loop 82 break; 83 } else { // if you got a newline, then clear currentLine 84 currentLine = ""; 85 } 86 } else if (c != '\ ') { // if you got anything else but a carriage return character, 87 currentLine += c; // add it to the end of the currentLine 88 } 89 } 90 } 91 // Clear the header variable 92 header = ""; 93 // Close the connection 94 client.stop(); 95 Serial.println("Client disconnected."); 96 Serial.println(""); 97 } 98}
untitled
arduino
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o */ 3 4 #include <WiFi.h> 5 6 const char* ssid = "user id"; 7 const char* password = "password"; 8 9 WiFiServer server(80); 10 11 String header; 12 String output26State = "off"; 13 String output27State = "off"; 14 15 const int output26 = 26; 16 const int output27 = 27; 17 18 void setup() { 19 Serial.begin(115200); 20 pinMode(output26, OUTPUT); 21 digitalWrite(output26, LOW); 22 digitalWrite(output27, LOW); 23 24 Serial.print("Connecting to "); 25 Serial.println(ssid); 26 WiFi.begin(ssid, password); 27 while (WiFi.status() != WL_CONNECTED) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println(""); 32 Serial.println("WiFi connected."); 33 Serial.println("IP address: "); 34 Serial.println(WiFi.localIP()); 35 server.begin(); 36 } 37 38 void loop(){ 39 WiFiClient client = server.available(); 40 if (client) { 41 Serial.println("New Client."); 42 String currentLine = ""; 43 while (client.connected()) { 44 if (client.available()) { 45 char c = client.read(); 46 Serial.write(c); 47 header += c; 48 if (c == '\ 49') { 50 if (currentLine.length() == 0) { 51 client.println("HTTP/1.1 200 OK"); 52 client.println("Content-type:text/html"); 53 client.println("Connection: close"); 54 client.println(); 55 56 // turns the GPIOs on and off 57 if (header.indexOf("GET /26/on") >= 0) { 58 Serial.println("GPIO 26 on"); 59 output26State = "on"; 60 digitalWrite(output26, HIGH); 61 } else if (header.indexOf("GET /26/off") >= 0) { 62 Serial.println("GPIO 26 off"); 63 output26State = "off"; 64 digitalWrite(output26, LOW); 65 } else if (header.indexOf("GET /27/on") >= 0) { 66 Serial.println("GPIO 27 on"); 67 output27State = "on"; 68 digitalWrite(output27, HIGH); 69 } else if (header.indexOf("GET /27/off") >= 0) { 70 Serial.println("GPIO 27 off"); 71 output27State = "off"; 72 digitalWrite(output27, LOW); 73 } 74 client.println("<!DOCTYPE html><html>"); 75 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\">"); 76 client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); 77 client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 78 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); 79 client.println(".button2 {background-color: #555555;}</style></head>"); 80 81 client.println("<body><h1>ESP32 Web Server</h1>"); 82 client.println("<p>GPIO 26 - State " + output26State + "</p>"); 83 84 85 86 87 88 89 client.println(); 90 break; 91 } else { currentLine = ""; } 92 } else if (c != '\ ') { currentLine += c; } 93 } 94 95 } 96 header = ""; 97 client.stop(); 98 Serial.println("Client disconnected."); 99 Serial.println(""); 100 } 101 }
untitled
arduino
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o */ 3 4 #include <WiFi.h> 5 6 const char* ssid = "user id"; 7 const char* password = "password"; 8 9 WiFiServer server(80); 10 11 String header; 12 String output26State = "off"; 13 String output27State = "off"; 14 15 const int output26 = 26; 16 const int output27 = 27; 17 18 void setup() { 19 Serial.begin(115200); 20 pinMode(output26, OUTPUT); 21 digitalWrite(output26, LOW); 22 digitalWrite(output27, LOW); 23 24 Serial.print("Connecting to "); 25 Serial.println(ssid); 26 WiFi.begin(ssid, password); 27 while (WiFi.status() != WL_CONNECTED) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println(""); 32 Serial.println("WiFi connected."); 33 Serial.println("IP address: "); 34 Serial.println(WiFi.localIP()); 35 server.begin(); 36 } 37 38 void loop(){ 39 WiFiClient client = server.available(); 40 if (client) { 41 Serial.println("New Client."); 42 String currentLine = ""; 43 while (client.connected()) { 44 if (client.available()) { 45 char c = client.read(); 46 Serial.write(c); 47 header += c; 48 if (c == '\n') { 49 if (currentLine.length() == 0) { 50 client.println("HTTP/1.1 200 OK"); 51 client.println("Content-type:text/html"); 52 client.println("Connection: close"); 53 client.println(); 54 55 // turns the GPIOs on and off 56 if (header.indexOf("GET /26/on") >= 0) { 57 Serial.println("GPIO 26 on"); 58 output26State = "on"; 59 digitalWrite(output26, HIGH); 60 } else if (header.indexOf("GET /26/off") >= 0) { 61 Serial.println("GPIO 26 off"); 62 output26State = "off"; 63 digitalWrite(output26, LOW); 64 } else if (header.indexOf("GET /27/on") >= 0) { 65 Serial.println("GPIO 27 on"); 66 output27State = "on"; 67 digitalWrite(output27, HIGH); 68 } else if (header.indexOf("GET /27/off") >= 0) { 69 Serial.println("GPIO 27 off"); 70 output27State = "off"; 71 digitalWrite(output27, LOW); 72 } 73 client.println("<!DOCTYPE html><html>"); 74 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\">"); 75 client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); 76 client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 77 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); 78 client.println(".button2 {background-color: #555555;}</style></head>"); 79 80 client.println("<body><h1>ESP32 Web Server</h1>"); 81 client.println("<p>GPIO 26 - State " + output26State + "</p>"); 82 83 84 85 86 87 88 client.println(); 89 break; 90 } else { currentLine = ""; } 91 } else if (c != '\r') { currentLine += c; } 92 } 93 94 } 95 header = ""; 96 client.stop(); 97 Serial.println("Client disconnected."); 98 Serial.println(""); 99 } 100 }
The code
arduino
Just copy and paste in Arduino IDE
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o */ 3 4 #include <WiFi.h> 5 6 const char* ssid = "user id"; 7 const char* password = "password"; 8 9 WiFiServer server(80); 10 11 String header; 12 String output26State = "off"; 13 String output27State = "off"; 14 15 const int output26 = 26; 16 const int output27 = 27; 17 18 void setup() { 19 Serial.begin(115200); 20 pinMode(output26, OUTPUT); 21 digitalWrite(output26, LOW); 22 digitalWrite(output27, LOW); 23 24 Serial.print("Connecting to "); 25 Serial.println(ssid); 26 WiFi.begin(ssid, password); 27 while (WiFi.status() != WL_CONNECTED) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println(""); 32 Serial.println("WiFi connected."); 33 Serial.println("IP address: "); 34 Serial.println(WiFi.localIP()); 35 server.begin(); 36 } 37 38 void loop(){ 39 WiFiClient client = server.available(); 40 if (client) { 41 Serial.println("New Client."); 42 String currentLine = ""; 43 while (client.connected()) { 44 if (client.available()) { 45 char c = client.read(); 46 Serial.write(c); 47 header += c; 48 if (c == '\n') { 49 if (currentLine.length() == 0) { 50 client.println("HTTP/1.1 200 OK"); 51 client.println("Content-type:text/html"); 52 client.println("Connection: close"); 53 client.println(); 54 55 // turns the GPIOs on and off 56 if (header.indexOf("GET /26/on") >= 0) { 57 Serial.println("GPIO 26 on"); 58 output26State = "on"; 59 digitalWrite(output26, HIGH); 60 } else if (header.indexOf("GET /26/off") >= 0) { 61 Serial.println("GPIO 26 off"); 62 output26State = "off"; 63 digitalWrite(output26, LOW); 64 } else if (header.indexOf("GET /27/on") >= 0) { 65 Serial.println("GPIO 27 on"); 66 output27State = "on"; 67 digitalWrite(output27, HIGH); 68 } else if (header.indexOf("GET /27/off") >= 0) { 69 Serial.println("GPIO 27 off"); 70 output27State = "off"; 71 digitalWrite(output27, LOW); 72 } 73 client.println("<!DOCTYPE html><html>"); 74 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\">"); 75 client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); 76 client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 77 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); 78 client.println(".button2 {background-color: #555555;}</style></head>"); 79 80 client.println("<body><h1>ESP32 Web Server</h1>"); 81 client.println("<p>GPIO 26 - State " + output26State + "</p>"); 82client.println(); 83 break; 84 } else { currentLine = ""; } 85 } else if (c != '\r') { currentLine += c; } 86 } 87 88 } 89 header = ""; 90 client.stop(); 91 Serial.println("Client disconnected."); 92 Serial.println(""); 93 } 94 }
the code
arduino
1/********* 2made by Kusnh13 3For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o 4*********/ 5 6// Load Wi-Fi library 7 8 9#include <WiFi.h> 10 11// Replace with your network credentials 12const char* ssid = "CG4-1102"; 13const char* password = "py79iq0h"; 14 15// Set web server port number to 80 16WiFiServer server(80); 17 18// Variable to store the HTTP request 19String header; 20 21// Auxiliar variables to store the current output state 22String output26State = "off"; 23String output27State = "off"; 24 25// Assign output variables to GPIO pins 26const int output26 = 26; 27const int output27 = 27; 28 29void setup() { 30 Serial.begin(115200); 31 // Initialize the output variables as outputs 32 pinMode(output26, OUTPUT); 33 pinMode(output27, OUTPUT); 34 // Set outputs to LOW 35 digitalWrite(output26, LOW); 36 digitalWrite(output27, LOW); 37 38 // Connect to Wi-Fi network with SSID and password 39 Serial.print("Connecting to "); 40 Serial.println(ssid); 41 WiFi.begin(ssid, password); 42 while (WiFi.status() != WL_CONNECTED) { 43 delay(500); 44 Serial.print("."); 45 } 46 // Print local IP address and start web server 47 Serial.println(""); 48 Serial.println("WiFi connected."); 49 Serial.println("IP address: "); 50 Serial.println(WiFi.localIP()); 51 server.begin(); 52} 53 54void loop(){ 55 WiFiClient client = server.available(); // Listen for incoming clients 56 57 if (client) { // If a new client connects, 58 Serial.println("New Client."); // print a message out in the serial port 59 String currentLine = ""; // make a String to hold incoming data from the client 60 while (client.connected()) { // loop while the client's connected 61 if (client.available()) { // if there's bytes to read from the 26 - State " + output26State + "</p>"); 62 // If the output26State is off, it displays the ON button 63 if (output26State=="off") { 64 client.println("<p><a href=\\"/26/on\\"><button class=\\"button\\">ON</button></a></p>"); 65 } else { 66 client.println("<p><a href=\\"/26/off\\"><button class=\\"button button2\\">OFF</button></a></p>"); 67 } 68 69 // Display current state, and ON/OFF buttons for GPIO 27 70 client.println("<p>GPIO 27 - State " + output27State + "</p>"); 71 // If the output27State is off, it displays the ON button 72 if (output27State=="off") { 73 client.println("<p><a href=\\"/27/on\\"><button class=\\"button\\">ON</button></a></p>"); 74 } else { 75 client.println("<p><a href=\\"/27/off\\"><button class=\\"button button2\\">OFF</button></a></p>"); 76 } 77 client.println("</body></html>"); 78 79 // The HTTP response ends with another blank line 80 client.println(); 81 // Break out of the while loop 82 break; 83 } else { // if you got a newline, then clear currentLine 84 currentLine = ""; 85 } 86 } else if (c != '\r') { // if you got anything else but a carriage return character, 87 currentLine += c; // add it to the end of the currentLine 88 } 89 } 90 } 91 // Clear the header variable 92 header = ""; 93 // Close the connection 94 client.stop(); 95 Serial.println("Client disconnected."); 96 Serial.println(""); 97 } 98}
The Code
arduino
Just upload it
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o */ 3 4 #include <WiFi.h> 5 6 const char* ssid = "user id"; 7 const char* password = "password"; 8 9 WiFiServer server(80); 10 11 String header; 12 String output26State = "off"; 13 String output27State = "off"; 14 15 const int output26 = 26; 16 const int output27 = 27; 17 18 void setup() { 19 Serial.begin(115200); 20 pinMode(output26, OUTPUT); 21 digitalWrite(output26, LOW); 22 digitalWrite(output27, LOW); 23 24 Serial.print("Connecting to "); 25 Serial.println(ssid); 26 WiFi.begin(ssid, password); 27 while (WiFi.status() != WL_CONNECTED) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println(""); 32 Serial.println("WiFi connected."); 33 Serial.println("IP address: "); 34 Serial.println(WiFi.localIP()); 35 server.begin(); 36 } 37 38 void loop(){ 39 WiFiClient client = server.available(); 40 if (client) { 41 Serial.println("New Client."); 42 String currentLine = ""; 43 while (client.connected()) { 44 if (client.available()) { 45 char c = client.read(); 46 Serial.write(c); 47 header += c; 48 if (c == '\n') { 49 if (currentLine.length() == 0) { 50 client.println("HTTP/1.1 200 OK"); 51 client.println("Content-type:text/html"); 52 client.println("Connection: close"); 53 client.println(); 54 55 // turns the GPIOs on and off 56 if (header.indexOf("GET /26/on") >= 0) { 57 Serial.println("GPIO 26 on"); 58 output26State = "on"; 59 digitalWrite(output26, HIGH); 60 } else if (header.indexOf("GET /26/off") >= 0) { 61 Serial.println("GPIO 26 off"); 62 output26State = "off"; 63 digitalWrite(output26, LOW); 64 } else if (header.indexOf("GET /27/on") >= 0) { 65 Serial.println("GPIO 27 on"); 66 output27State = "on"; 67 digitalWrite(output27, HIGH); 68 } else if (header.indexOf("GET /27/off") >= 0) { 69 Serial.println("GPIO 27 off"); 70 output27State = "off"; 71 digitalWrite(output27, LOW); 72 } 73 client.println("<!DOCTYPE html><html>"); 74 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\">"); 75 client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"); 76 client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 77 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); 78 client.println(".button2 {background-color: #555555;}</style></head>"); 79 80 client.println("<body><h1>ESP32 Web Server</h1>"); 81 client.println("<p>GPIO 26 - State " + output26State + "</p>"); 82 83 84 85 86 87 88 client.println(); 89 break; 90 } else { currentLine = ""; } 91 } else if (c != '\r') { currentLine += c; } 92 } 93 94 } 95 header = ""; 96 client.stop(); 97 Serial.println("Client disconnected."); 98 Serial.println(""); 99 } 100 }
untitled
arduino
1 /* made by Kusnh13 2 For refrence watch YouTube video:-https://youtu.be/Hgq2KX5w-_o 3 */ 4 5 #include <WiFi.h> 6 7 const char* ssid = "user id"; 8 9 const char* password = "password"; 10 11 WiFiServer server(80); 12 13 14 String header; 15 String output26State = "off"; 16 String output27State 17 = "off"; 18 19 const int output26 = 26; 20 const int output27 = 27; 21 22 23 void setup() { 24 Serial.begin(115200); 25 pinMode(output26, OUTPUT); 26 27 digitalWrite(output26, LOW); 28 digitalWrite(output27, LOW); 29 30 Serial.print("Connecting 31 to "); 32 Serial.println(ssid); 33 WiFi.begin(ssid, password); 34 while (WiFi.status() 35 != WL_CONNECTED) { 36 delay(500); 37 Serial.print("."); 38 } 39 Serial.println(""); 40 41 Serial.println("WiFi connected."); 42 Serial.println("IP address: "); 43 44 Serial.println(WiFi.localIP()); 45 server.begin(); 46 } 47 48 void loop(){ 49 50 WiFiClient client = server.available(); 51 if (client) { 52 Serial.println("New 53 Client."); 54 String currentLine = ""; 55 while (client.connected()) 56 { 57 if (client.available()) { 58 char c = client.read(); 59 Serial.write(c); 60 61 header += c; 62 if (c == '\ 63') { 64 if (currentLine.length() 65 == 0) { 66 client.println("HTTP/1.1 200 OK"); 67 client.println("Content-type:text/html"); 68 69 client.println("Connection: close"); 70 client.println(); 71 72 // turns 73 the GPIOs on and off 74 if (header.indexOf("GET /26/on") >= 0) { 75 Serial.println("GPIO 76 26 on"); 77 output26State = "on"; 78 digitalWrite(output26, HIGH); 79 } 80 else if (header.indexOf("GET /26/off") >= 0) { 81 Serial.println("GPIO 26 off"); 82 83 output26State = "off"; 84 digitalWrite(output26, LOW); 85 } else if (header.indexOf("GET 86 /27/on") >= 0) { 87 Serial.println("GPIO 27 on"); 88 output27State = "on"; 89 90 digitalWrite(output27, HIGH); 91 } else if (header.indexOf("GET /27/off") 92 >= 0) { 93 Serial.println("GPIO 27 off"); 94 output27State = "off"; 95 96 digitalWrite(output27, LOW); 97 } 98 client.println("<!DOCTYPE html><html>"); 99 100 client.println("<head><meta name=\\"viewport\\" content=\\"width=device-width, 101 initial-scale=1\\">"); 102 client.println("<style>html { font-family: Helvetica; 103 display: inline-block; margin: 0px auto; text-align: center;}"); 104 client.println(".button 105 { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;"); 106 107 client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: 108 pointer;}"); 109 client.println(".button2 {background-color: #555555;}</style></head>"); 110 111 112 client.println("<body><h1>ESP32 Web Server</h1>"); 113 client.println("<p>GPIO 114 26 - State " + output26State + "</p>"); 115 116 117 118 119 120 121 122 client.println(); 123 break; 124 } else { currentLine = ""; } 125 } else 126 if (c != '\ ') { currentLine += c; } 127 } 128 129 } 130 header = ""; 131 132 client.stop(); 133 Serial.println("Client disconnected."); 134 Serial.println(""); 135 136 } 137 }
Comments
Only logged in users can leave comments
kunshmaurya
0 Followers
•0 Projects
0