ESP8266 Unwanted delay in buttons

I'm trying to build a remote control with an ESP8266 that calls a URL each time a button is pressed.

This functionality is working but I need to wait for 5 seconds each time I press a button, next button pressed in the period in between will result in no action at all, is like having a sleep or delay function but I don't have any.

I'm attaching pictures of my board and this is the code:

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

void setup() {
  
  Serial.begin(115200);                 //Serial connection
  WiFi.begin("Fibertel WiFi731 2.4", "0052843636");   //WiFi connection
 
  while (WiFi.status() != WL_CONNECTED) {  //Wait for the WiFI connection completion
 
    delay(500);
    Serial.println("Waiting for connection");
 
  }
  pinMode( D1, INPUT );
  pinMode( D2, INPUT );
  pinMode( D3, INPUT );
  pinMode( D4, INPUT );
  pinMode( D5, INPUT );
  pinMode( D6, INPUT );
  pinMode( D7, INPUT );
  pinMode( D8, INPUT );
  pinMode( LED_BUILTIN, OUTPUT );

}

void loop() {

  byte button1State = digitalRead( D1 );
  if( button1State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=0");  

  byte button2State = digitalRead( D2 );
  if( button2State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=1");

  byte button5State = digitalRead( D5 );
  if( button5State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=3");
  
  byte button6State = digitalRead( D6 );
  if( button6State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=4");

  byte button7State = digitalRead( D7 );
  if( button7State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=5");

  byte button3State = digitalRead( D8 );
  if( button3State == HIGH )
    toggleLights("http://192.168.0.199/leds.cgi?led=2");
}

void toggleLights(String destination) {
 if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
 
   HTTPClient http;    //Declare object of class HTTPClient
 
   http.begin(destination);      //Specify request destination
   http.addHeader("Content-Type", "text/plain");  //Specify content-type header
   http.setAuthorization("b", "b");  //Specify username/password header
 
   int httpCode = http.GET();
   String payload = http.getString();                  //Get the response payload
 
   Serial.println(httpCode);   //Print HTTP return code
   Serial.println(payload);    //Print request response payload
 
   http.end();  //Close connection
 
 }else{
 
    Serial.println("Error in WiFi connection");   
 
 }
}

Why don't you blink your builtin LED ON at the start of toggleLights() and OFF at the end and see how long it is taking for that code to execute?

What does leds.cgi get up to and how ?

blh64:
Why don't you blink your builtin LED ON at the start of toggleLights() and OFF at the end and see how long it is taking for that code to execute?

Great I did that and realized that the getString method is taking 5 seconds to come back.

Is there any way to do the request but not wait for the answer?

Thanks!

UKHeliBob:
What does leds.cgi get up to and how ?

It's a webserver that control lights, it has it's own web, this is the link of the button, but when I do use the web is instant, in this case the light reaction is instant but it takes 5 seconds to come back, it's something weird in my opinion.

It's a webserver that control lights, it has it's own web, this is the link of the button, but when I do use the web is instant, in this case the light reaction is instant but it takes 5 seconds to come back,

So you are saying that the webserver responds straight away but the sketch is halted by the getString() ? I think the webpage's html might be a suspect.

Funny little coincidence... The default timeout for httpClient is ..... 5 seconds

blh64:
Funny little coincidence... The default timeout for httpClient is ..... 5 seconds

Hence my inquiry. Possibility exist the client is waiting for