esp8266 webserver very slow

HELLO system works normally, I connect to my own network with wifi manager. but relay control active passive very slow.I push the button after 3-4 seconds, how can I accelerate it a little bit faster?

// esp librari
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>     



#define D0 16            
#define wifipin  D0        
#define D8 15
#define ConfigWiFi_Pin D8 
#define ESP_AP_NAME "EVOTO"

// server protum
WiFiServer server(80);

// http istekleri
String header;

// röle duurumu
String relay1State = "kapat";
String relay2State = "kapat";
String relay3State = "kapat";
String relay4State = "kapat";

// röle pinleri
const int relay1 = 5; // GPIO5 D1
const int relay2 = 4; // GPIO4 D2
const int relay3 = 0; // GPIO0 D3
const int relay4 = 2; // GPIO2 D4

void setup() {
 
   // initialize pin D0 as an output.
  pinMode(wifipin, OUTPUT);
  pinMode(ConfigWiFi_Pin,INPUT_PULLUP);
  Serial.begin(115200);
 digitalWrite(wifipin,LOW);//Turn on the LED
 WiFiManager wifiManager;
  if(digitalRead(ConfigWiFi_Pin) == LOW) // Press button
  {
    //reset saved settings
    wifiManager.resetSettings(); // go to ip 192.168.4.1 to config
  }
 wifiManager.autoConnect(ESP_AP_NAME); 
  while (WiFi.status() != WL_CONNECTED) 

  // pinlerin durumu giriş/çıkış
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  // çıkış ayaları
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);

  // hadi ağa bağlanalım
  
  {
    delay(500);
    Serial.print(".");
  }
Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  digitalWrite(wifipin,HIGH);
  
  // espnin ip adresini yazdıralım
  Serial.println("");
  Serial.println("Kablosuz Bağlandı.");
  Serial.println("Sunucu Ip Adresi: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

void loop() {
  
   digitalWrite(D8, HIGH); 
 delay(2000);
 digitalWrite(D8, LOW);  
 delay(2000);
  WiFiClient client = server.available();

  if (client) {
    Serial.println("Yeni Veri.");
    String currentLine = "";
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        header += c;
        if (c == '\n') {
     
   
          if (currentLine.length() == 0) {
  
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            // turns the GPIOs on and off
            if (header.indexOf("GET /5/ac") >= 0)
            {
              Serial.println("GPIO 5 ac");
              relay1State = "ac";
              digitalWrite(relay1, LOW);
            }
            else if (header.indexOf("GET /5/kapat") >= 0)
            {
              Serial.println("GPIO 5 kapat");
              relay1State = "kapat";
              digitalWrite(relay1, HIGH);
            }
            else if (header.indexOf("GET /4/ac") >= 0) {
              Serial.println("GPIO 4 ac");
              relay2State = "ac";
              digitalWrite(relay2, LOW);
            }
            else if (header.indexOf("GET /4/kapat") >= 0) {
              Serial.println("GPIO 4 kapat");
              relay2State = "kapat";
              digitalWrite(relay2, HIGH);
            }
            else if (header.indexOf("GET /0/ac") >= 0)
            {
              Serial.println("GPIO 0 ac");
              relay3State = "ac";
              digitalWrite(relay3, LOW);
            }
            else if (header.indexOf("GET /0/kapat") >= 0)
            {
              Serial.println("GPIO 0 kapat");
              relay3State = "kapat";
              digitalWrite(relay3, HIGH);
            }
            else if (header.indexOf("GET /2/ac") >= 0) {
              Serial.println("GPIO 2 ac");
              relay4State = "ac";
              digitalWrite(relay4, LOW);
            }
            else if (header.indexOf("GET /2/kapat") >= 0) {
              Serial.println("GPIO 2 kapat");
              relay4State = "kapat";
              digitalWrite(relay4, HIGH);
            }

            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".button { background-color: #195B6A; border: none; color: white; padding: 12px 24px;");
            client.println("text-decoration: none; font-size: 20px; margin: 2px; cursor: pointer;}");
            client.println(".button2 {background-color: #77878A;}</style></head>");

            // Web Page Heading
            client.println("<body><h1>Evoto Ev Kontrol Sistemi</h1>");

            // Display current state, and ON/OFF buttons for GPIO 5
            client.println("<p>Buton 1 Durumu " + relay1State + "</p>");
            // If the relay1State is off, it displays the ON button
            if (relay1State == "kapat") {
              client.println("<p><a href=\"/5/ac\"><button class=\"button\">Aktif</button></a></p>");
            } else {
              client.println("<p><a href=\"/5/kapat\"><button class=\"button button2\">Pasif</button></a></p>");
            }

            // Display current state, and ON/OFF buttons for GPIO 4
            client.println("<p>Buton 2 Durumu " + relay2State + "</p>");
            // If the relay2State is off, it displays the ON button
            if (relay2State == "kapat") {
              client.println("<p><a href=\"/4/ac\"><button class=\"button\">Aktif</button></a></p>");
            } else {
              client.println("<p><a href=\"/4/kapat\"><button class=\"button button2\">Pasif</button></a></p>");
            }

            // Display current state, and ON/OFF buttons for GPIO 0
            client.println("<p>Buton 3 Durumu " + relay3State + "</p>");
            // If the relay1State is off, it displays the ON button
            if (relay3State == "kapat") {
              client.println("<p><a href=\"/0/ac\"><button class=\"button\">Aktif</button></a></p>");
            } else {
              client.println("<p><a href=\"/0/kapat\"><button class=\"button button2\">Pasif</button></a></p>");
            }

            // Display current state, and ON/OFF buttons for GPIO 2
            client.println("<p>Buton 4 Durumu " + relay4State + "</p>");
            // If the relay2State is off, it displays the ON button
            if (relay4State == "kapat") {
              client.println("<p><a href=\"/2/ac\"><button class=\"button\">Aktif</button></a></p>");
            } else {
              client.println("<p><a href=\"/2/kapat\"><button class=\"button button2\">Pasif</button></a></p>");
            }

            client.println("</body></html>");

   
            client.println();
          break;
          } else { 
            currentLine = "";
          }
        } else if (c != '\r') { 
          currentLine += c; 
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Sunucu Kapandı.");
    Serial.println("");
  }
}

remove the two 2 seconds delays. use BlinkWithoutDelay example for heartbeat LED

how can I accelerate it a little bit faster?

Get

rid

of

all

delay()s.

thanks friends :slight_smile:

friends this is the code below, the alarm system is using a virtual 0 pin. to turn the alarm on and off, to my existing code, when I've edited it, I get errors, can you direct me?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

char auth[] = "d37110b7c3884a92a3f4439ffe4d6c47";
char ssid[] = "okhan";
char pass[] = "atakan2009";
char server[] = "blynk-cloud.com";

#define ledPin 2 
#define pirPin 0

int pirState;
int val;
int x;

SimpleTimer timer;

BLYNK_CONNECTED() {
      Blynk.syncVirtual(V0);
  }

BLYNK_WRITE(V0){
 x = param.asInt();
 }

void PIRval(){3
val = digitalRead(pirPin);
    if (val == HIGH) {
      digitalWrite(ledPin, HIGH);  
      }
      else {
        digitalWrite(ledPin, LOW); 
      }
   }

  void pir(){
  if (x == 1){
    if (digitalRead(pirPin) == HIGH){
 Blynk.notify("EVDE HAREKET ALGILANDI");
 }
    }
  }

void setup(){
  Blynk.begin (auth, ssid, pass, server, 8442);//local server
   // You can change server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);

  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);

  timer.setInterval(1000L, PIRval);
 timer.setInterval(1000L, pir);
   }

void loop(){
   Blynk.run();
   timer.run();
}

I get errors, can you direct me?

Yes, indeed. I direct you to POST THE ERRORS.

I want to connect the motion sensor, and next to the relay control buttons, the alarm is on - the alarm off-button is added, and when you want to disable the motion detector, you can help. I don't want to use blynk.

ykilicaslan:
I push the button after 3-4 seconds, how can I accelerate it a little bit faster?

Juraj:
remove the two 2 seconds delays.

That just put me in a happy mood, thank you all!