Web server asynchronous, concurrent process

Hi
I have written a ESP8266 web server with parameter via arduino ide.

My problem is:
when I call a web serever's method on ESP8266, I send it a command and timing to do it, after I have to wait the action end. If I run another time the same command "tapparelle", the latest command don't run immediatly. I have to wait the previus command.

How I can resolve this problem?

Thanks a lot

This is my code

#include "ESP8266WiFi.h"
#include "ESP8266WebServer.h"
#include <ESP8266HTTPUpdateServer.h>
 
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;


int tap1_1 = 5; // D1 , gpio5
int tap1_2 = 4; //  D2, gpio4

int tap2_1 = 14; //  D5, gpio14
int tap2_2 = 12; //  D6 , gpio12 

int tap3_1; //  D5, gpio14
int tap3_2; //  D6 , gpio12


int portone;// = 12; //D7, gpio13

int pwOFF=0;
int pwON=1;

char valTemp[20];

void setup() {
 
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  settingPIN();
  HTTPUpdateConnect();
  WiFi.begin("MyWiFi", "MyWiFi");  //Connect to the WiFi network
 
  while (WiFi.status() != WL_CONNECTED) {  //Wait for connection
 
    delay(500);
    Serial.println("Waiting to connect…");
 
  }
 
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //Print the local IP
 
  //*********************************************************************************************

  server.on("/", handleRootPath);    //Associate the handler function to the path

  //*********************************************************************************************
  server.on("/tapparelle", handleTapparelle);   //Associate the handler function to the path

  server.on("/portone", handlePortone);   //Associate the handler function to the path



  
  server.on("/update", [](){ // Se viene richiamato la pagina statuss
    HTTPUpdateConnect();
  });
  //*********************************************************************************************
  server.on("/reboot", [](){ // Se viene richiamato la pagina statuss
    ESP.restart();
  });
  //*********************************************************************************************

  
  server.begin();                    //Start the server
  Serial.println("Server listening");
 
}
 

  //*********************************************************************************************
void handlePortone() { //Handler
    int valTemp;
    String msgTemp="";
    String message = "Number of args received:";
    message += server.args();            //Get number of parameters
    message += "\n";                            //Add a new line

    for (int i = 0; i < server.args(); i++) {

      message += "Arg number" + (String)i + " > ";   //Include the current iteration value
      message += server.argName(i) + ": ";     //Get the name of the parameter
      message += server.arg(i) + "\n\n";              //Get the value of the parameter
      msgTemp=server.arg(i);
      
      if (i==0 and server.argName(i)=="temp") {
        valTemp = msgTemp.toInt();
        Serial.println("variabile tempo");
        Serial.println(valTemp);  
        digitalWrite(portone, pwON); //
        delay(valTemp);
        digitalWrite(portone, pwOFF); //
        message += "parametro tempo corretto";
        server.send(200, "text/plain", message);       //Response to the HTTP request
        
      }else{
        message += "parametro tempo non corretto o non impostate";
        server.send(200, "text/plain", message);       //Response to the HTTP request
      }

    } 
   
  }


//*****************************************************************************************************
void handleTapparelle() { //Handler

  //esempio link
  //http://10.20.101.87/tapparelle?tap1=up&time=18
  
  String message = "Number of args received:";
  String relAlim, relDir;
  
  int valDurata, valStatus,GpioAlim,GpioDir;
  
  message += server.args();            //Get number of parameters
  message += "\n";                            //Add a new line

  for (int i = 0; i < server.args(); i++) {

    message += "Arg number" + (String)i + " > ";   //Include the current iteration value
    message += server.argName(i) + ": ";     //Get the name of the parameter
    message += server.arg(i) + "\n\n";              //Get the value of the parameter

  } 

  if (server.args()==2) {     //parametri di movimento: su/giu e attivazione direzione
    //message += "parametri OK";
    Serial.println("parametri OK");

    if (server.argName(0)=="tap1") {
        GpioAlim=tap1_1;
        GpioDir=tap1_2;

    } else if (server.argName(0)=="tap2"){
        GpioAlim=tap2_1;
        GpioDir=tap2_2;

    } else if (server.argName(0)=="tap3"){
        GpioAlim=tap3_1;
        GpioDir=tap3_2;
    }
    
    valStatus = digitalRead(GpioAlim);
    Serial.print("stato gpio alim:");
    Serial.println(valStatus);
 
    //verifico valore dell'alimentazione della tapparella
    if (valStatus==0) {
        valDurata = server.arg(1).toInt();
        Serial.print("durata movimento tap:");
        Serial.println(valDurata);
        
        relDir=server.arg(0); //direzione
        Serial.print("direzione tap:");
        Serial.println(relDir);
        if (relDir=="up") {
            digitalWrite(GpioAlim, pwON); //
            //delay(100);
            digitalWrite(GpioDir, pwON); //
            delay(valDurata);
        
            digitalWrite(GpioAlim, pwOFF); //
            digitalWrite(GpioDir, pwOFF); //
        } else if (relDir=="down") {
            digitalWrite(GpioAlim, pwON); //
            //delay(100);
            digitalWrite(GpioDir, pwOFF); //
            delay(valDurata);
        
            digitalWrite(GpioAlim, pwOFF); //
            digitalWrite(GpioDir, pwOFF); //
          
        }
        //Serial.println("gpio dir:");
        //GpioDir=relDir.toInt();
        Serial.println(GpioDir);
        
        
        
        
        //message += "parametro tempo corretto";
        server.send(200, "text/plain", message);       //Response to the HTTP request

        
      
     } else {
        message += "tap in funzione";
      
      
    }
  }else {
    message += "parametri KO";
  }
  
  server.send(200, "text/plain", message);       //Response to the HTTP request

}


 

 //*********************************************************************************************



void loop() {
 
  server.handleClient();         //Handling of incoming requests
 
}
 
void handleRootPath() {            //Handler for the rooth path
 
  server.send(200, "text/plain", "esp8266");
 
}

void HTTPUpdateConnect() {  
  httpUpdater.setup(&server);
  server.begin();
}



void settingPIN() {
  //setto i pinout ad OUT e a valore HIGH
  
  pinMode(tap1_1, INPUT);  
  pinMode(tap1_2, INPUT);
  digitalWrite(tap1_1, pwOFF);
  digitalWrite(tap1_2, pwOFF);

  pinMode(tap2_1, INPUT);
  pinMode(tap2_2, INPUT);
  digitalWrite(tap2_1, pwOFF);
  digitalWrite(tap2_2, pwOFF);

  pinMode(portone, INPUT);
  digitalWrite(portone, pwOFF);  

  delay(3000);

  
  pinMode(tap1_1, OUTPUT);  
  pinMode(tap1_2, OUTPUT);
  digitalWrite(tap1_1, pwOFF);
  digitalWrite(tap1_2, pwOFF);

  pinMode(tap2_1, OUTPUT);
  pinMode(tap2_2, OUTPUT);
  digitalWrite(tap2_1, pwOFF);
  digitalWrite(tap2_2, pwOFF);

  pinMode(portone, OUTPUT);
  digitalWrite(portone, pwOFF);

}

How I can resolve this problem?

You can't. The process you are using gets some data from a client, parses the data, does something (not much in your case), and generates a reply to that client. Only when dealing with that client is complete can the program consider handling another client.

Thanks a lot for your reply.
So you suggest to write different handle with parameter, so I can call the handle in the same time without problem. Correct?

Thanks

use Ajax

for more

xhttp.open("GET/POST", "/path", true);

that 'true' parameter does 'serve requests ' thing asynchronously/concurrently

rdie77:
Thanks a lot for your reply.
So you suggest to write different handle with parameter, so I can call the handle in the same time without problem. Correct?

Thanks

A reality check seems to be in order. You are using a very low powered device as a server, and yet you seem to expect the same performance as a much more capable system with an operating system. Tain't gonna happen.