Espe8266 wifi serve alguem ajuda!

ESTOU TENTANDO USAR UM TEMPORIZADOR MILLIS OU OUTRO MAS NAO FUNCIONA QUANDO COLOCO NO CODIGO WIFIWEBSERVE E SOU NOVATO EM ARDUINO E ESP, E SE ALGUEM TIVER UM TEMPORIZADOR MELHOR SERIA BOM??



#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "KNUPFER"   
#define STAPSK "0800.com"
#define pino1 D3
#define pino2 D4

#endif

const char* ssid = STASSID;
const char* password = STAPSK;
int RELE1 = 2;
int RELE2 = 2;



// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);

   

  // RELE LIGA DESLIGA
  pinMode (pino1, OUTPUT);
  pinMode (pino2, OUTPUT);
  

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print(F("Connecting to "));
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();
  Serial.println(F("WiFi connected"));

  // Start the server
  server.begin();
  Serial.println(F("Server started"));

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.accept();
  if (!client) { return; }
  Serial.println(F("new client"));

  client.setTimeout(5000);  // default is 1000

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(F("request: "));
  Serial.println(req);
  
    
     //RELE 1 FUNCINANDO recebe dados app////////////////////
     if (req.indexOf(F("/RELE1/ON")) != -1) {
      RELE1 =1;
  } 
      if (req.indexOf(F("/RELE1/OFF")) != -1) {
      RELE1 =2; 
  }
        //RELE 2  RECEBE DADOS///////////////////////////
         if (req.indexOf(F("/RELE2/ON")) != -1) {
      RELE2 =1;
  } 
      if (req.indexOf(F("/RELE2/OFF")) != -1) {
      RELE2 =2; 
  }
        
     //aplica dados RELE 1//////////////////////////
   if (RELE1 == 1){ 
    digitalWrite( pino1, HIGH);


    } 
   
    if (RELE1 == 2) { 

     digitalWrite( pino1, LOW);
   } 
   ////////////////////////////////////



     //aplica dados RELE 2//////////////////////////
    if (RELE2 == 1){ 
    digitalWrite( pino2, HIGH);
   } 
   
    if (RELE2 == 2) { 
   digitalWrite( pino2, LOW);
   } 

/////////////////////////////////////



              
  // read/ignore the rest of the request
  // do not client.flush(): it is for output only, see below
  while (client.available()) {
    // byte by byte is not very efficient
    client.read();
  }

  // Send the response to the client
  // it is OK for multiple small client.print/write,
  // because nagle algorithm will group them into one single packet
  client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nRAI SERVER "));
  client.print(F("<br><br>Click <a href='http://"));
  client.print(WiFi.localIP());
  client.print(F("/gpio/1'>here</a> to switch LED GPIO on, or <a href='http://"));
  client.print(WiFi.localIP());
  client.print(F("/gpio/0'>here</a> to switch LED GPIO off.</html>"));
 // client.print(type="text/javascript"> var teste = "99");
  //client.print("<h1><center>" + String(xx) + "</center></h1>");

  // The client will actually be *flushed* then disconnected
  // when the function returns and 'client' object is destroyed (out-of-scope)
  // flush = ensure written data are received by the other side
  Serial.println(F("Disconnecting from client"));


   ///////////TESTE ENVIO





}

*PRIMEIRO TEMPORIZADOR ,E ESSE E UMA BELEZA SOZINHO *


/*
 * Exemplo de código usando millis()
 */
// Inicia variáveis de tempo
unsigned long millisTarefa1 = millis();
unsigned long millisTarefa2 = millis();
 int liga_ou_desligar1 = 1;
 int liga_ou_desligar2 = 1;
 long tempo1 = 5000;
 long tempo2 = 10000;
 unsigned long millisSegundo1 ;
 unsigned long millisSegundo2;
// Iniciação
void setup(){
  // Inicia comunicação na porta serial
  Serial.begin(115200);
  // Define pinos dos leds como saída
  pinMode(D4, OUTPUT);
  pinMode(D3, OUTPUT);
  
}
// Laço perpétuo
void loop(){
  // Executa tarefa 1
  tarefa1();
  tarefa2();
  
}
 
void tarefa1(){
  // Verifica se já passou 200 milisegundos

   if(liga_ou_desligar1 == 1){

         if((millis() - millisTarefa1) < tempo1){
            // Acende o led do pino 7
         digitalWrite(D4, HIGH);
           millisSegundo1 = ( tempo1 - (millis() - millisTarefa1 ));
             Serial.println(millisSegundo1 /1000);
         }else{
          // Apaga o led do pino 7
           digitalWrite(D4, LOW);
         }
           }else if(liga_ou_desligar1==0){
           digitalWrite(D4, LOW);


           }

}

void tarefa2(){
  // Verifica se já passou 200 milisegundos

   if(liga_ou_desligar2 == 1){

         if((millis() - millisTarefa2) < tempo2){
            // Acende o led do pino 7
         digitalWrite(D3, HIGH);
           millisSegundo2 = ( tempo2 - (millis() - millisTarefa2));
             Serial.println(millisSegundo2 /1000);
         }else{
          // Apaga o led do pino 7
           digitalWrite(D3, LOW);
         }
           }else if(liga_ou_desligar2==0){
           digitalWrite(D3, LOW);


           }

}
 
 

*2 TEMPORIZADOR MAIS ESSE E MEIO RUIM PRA MIN MAIS VOU MOSTRA ASSIM MESMO

#include <Crescer.h>

Tempora temp1;      
Tempora temp2;    
Tempora temp3; 
int analogica;
int refr = 0;
int teste = 1;
int teste2 = 1;
int pisca = 0;

void setup() {
Serial.begin(115200);
delay(5000);
Serial.println("teste     testeeeeeeeeeeeeeeeee");

 

temp1.defiSP(10000);
temp2.defiSP(7000);
temp3.defiSP(5000);

}

void loop() {

     Serial.println(".....");
    
  //Aguarda intervalo de tempo em milissegundos
  delay(1000);
    
  //Apaga o led
  Serial.println("...........");
    
  //Aguarda intervalo de tempo em milissegundos
  delay(1000);
 
  // if (temp1.Saida(1)){
     // Serial.println("teste      1111");
      // temp1.Saida(0);

  ///   }

       if(teste== 1 & temp1.Saida(1)){
            Serial.println("test 1111111111111111");
             temp1.Saida(0); 
              teste = 0;
              


        }
             

             if(teste2== 1 & temp2.Saida(1)){
            Serial.println("teste  22222222222222");
             temp2.Saida(0); 
              teste2 = 0;
              


        }




}