Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Emiliano del Campo
#80346 Sometimes the webserver get stuck with a new client and doesn't disconnect it.

Code: Select all#include <ESP8266WiFi.h>
#include <Servo.h>
Servo servo1;

int pinservo = D2;
int pulsomin = 1000;
int pulsomax = 2000;
 
const char* ssid = "Manuela";
const char* password = "manuel34068833";
 
int ledPin = D4;
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  servo1.attach(pinservo,pulsomin,pulsomax);
  servo1.write(50);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  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 : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // 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(100);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("Abrir") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
    servo1.write(39);
    delay(400);
    servo1.write(50);
  }
  if (request.indexOf("AbrirYcerrar") != -1){
    digitalWrite(ledPin, LOW);
    value = LOW;
    servo1.write(39);
    delay(400);
    servo1.write(50);
    delay(55000);
    servo1.write(39);
    delay(400);
    servo1.write(50);
  }
 
 
 
  // 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.println("<style> a {font-size: 104px;background-color: #4dd2ff;color:white;}</style>");


  client.println("<br><br>");
  client.println("<h1>Clickea <a href=\"/Abrir\">ACA</a> Para abrir el porton</h1>");
 
  client.println("</html>");
 
  delay(100);
  Serial.println("Client disconnected");
  Serial.println("");
}
 


The monitor output..

Code: Select all 12:53:13.258 -> Connecting to Manuel
12:53:13.750 -> ....
12:53:15.256 -> WiFi connected
12:53:15.256 -> Server started
12:53:15.256 -> Use this URL : http://192.168.1.48/
12:53:17.853 -> new client
12:53:17.923 -> GET / HTTP/1.1
12:53:18.031 -> Client disconnected
12:53:18.031 ->
12:53:18.031 -> new client
12:53:18.357 -> GET /favicon.ico HTTP/1.1
12:53:18.445 -> Client disconnected
12:53:18.445 ->
12:53:18.935 -> new client  //stucked here