Problem while dealing with code.

Hello friends,

I am doing my graduation project like led on/off using web button and push button. In web 'on'button is pressed then led on and the status of the led is displayed in web browser. when we press push button the led is off but led status is not displayed in web browser. please help me how to solve this problem.

 #include <ESP8266WiFi.h>
#include <Bounce2.h>
const char* ssid = "SSID";
const char* password = "PASSWORD";
const byte SwitchPins[] = {4}; 
Bounce switches[sizeof(SwitchPins)];
int ledpin = 13; 

IPAddress ip(********);  //Node static IP
IPAddress gateway(*****);
IPAddress subnet(********);
WiFiServer server(***);

void setup() {
  Serial.begin(115200);
  delay(10);
  
  for(byte i = 0; i < sizeof(SwitchPins); i++){
    switches[i].attach(SwitchPins[i], INPUT_PULLUP); //use INPUT if you have external pull up/down resistors
  }
  
  pinMode(ledpin, OUTPUT);
    
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
void loop()
{
  webloop();
  switchloop();
}
void webloop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value1 = LOW;
   
  if (request.indexOf("/button1=on") != -1)  {
    digitalWrite(ledpin, LOW);
        value1 = HIGH;
  }
  if (request.indexOf("/button1=off") != -1)  {
    digitalWrite(ledpin, HIGH);
    value1 = LOW;
    }
  
    // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.print("<TITLE>Home Automation</TITLE>\r\n");
  client.print("</HEAD>\r\n");
  client.print("<BODY>\r\n");
  client.print("<H1>My Smart Home System</H1>\r\n");
   
  client.print("led is now: ");
   if(value1 == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.print("<a href=\"/button1=on\"><button>ON</button></a>&nbsp;<a href=\"/button1=off\"><button>OFF</button></a></p>");
  client.println("\n");
  client.println("\n");
  client.println("</html>");
  client.println("

");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
 
}
 void switchloop()
 {
 
  for(byte i = 0; i < sizeof(SwitchPins); i++){
    switches[i].update();
  }
  
  //I here assume pull up resistors (like with INPUT_PULLUP)
  if(switches[0].fell()){
    digitalWrite(ledpin, HIGH);
   }
  
  if(switches[0].rose()){
    digitalWrite(ledpin, LOW);
   }
  }

I'd make better use of the F() macro, then retest.

Please explain more what you expect your program to do and what it's doing that does not meet your expectations.

Please always use Tools > Auto Format before posting code to the forum. It's very difficult to read your code with the random indentation.

AWOL:
I'd make better use of the F() macro, then retest.

They're using an ESP8266, the problem is certainly not caused by a shortage of SRAM. That's not to say that you should forget about efficient use of memory but it's certainly less of a concern and actually not using it can cause the Print class functions to run significantly faster.

If i am using web browser to switch on/off led the led is on/off according to the button i pressed and the led status also displayed in web browser. If i press push button led is on and the status of led is display in serial monitor but i want it to display on web browser.

aswiniummadi:
status of led is display in serial monitor

I don't see anything in your code that would do that. Are using a different version than what you posted?

I am using above code only serial.print("on") & serial.print("off") is used display the led status on serial monitor.

I wrote two void loops in the code. one loop is for web button creation and operation. another one is for switch operations. when i push the push button then it will goes to switch loop to perform switch operation. but i want to do is when i press a push button then it will goes to switch loop condition and also integrate with web loop to display led status in web browser. please help where i want to modify the code.

I wrote two void loops in the code.

You can only have one function called "loop" in a sketch.

In the code i mentioned two loops like webloop and switch loop.

Void setup()
{

}
void loop(){
webloop();
switchloop();
}

void webloop{
}
void switchloop() 
{

}