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

Moderator: igrr

User avatar
By M0ebius
#18120 I have a problem with the ESP8266WebServer.
The helloserver example compiles, uploads and runs - but it does not accept connections.
I always get a connection timeout.

In the file esp8266webserver.cpp, the line "WiFiClient client = _server.available();" never returns a valid client.

But it works, if i implement a server "by hand":
Code: Select all#include <ESP8266WiFi.h>
const char* ssid = "....";
const char* password = "...";

WiFiServer server(80);

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFiStart();
}

void WiFiStart()
{
  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");
 
  server.begin();
  Serial.println("Server started");

  Serial.println(WiFi.localIP());
}

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");
  unsigned long ultimeout = millis()+250;
  while(!client.available() && (millis()<ultimeout) )
  {
    delay(1);
  }
  if(millis()>ultimeout)
  {
    Serial.println("client connection time-out!");
    return;
  }
 
  // Read the first line of the request
  String sRequest = client.readStringUntil('\r');
  //Serial.println(sRequest);
  client.flush();
 
 // Send the response to the client
  client.print("header");
  client.print("body");
 
  // and stop the client
  client.stop();
  Serial.println("Client disonnected");
}

How can i fix it?
(Win 8.1-64, Arduino 1.6.4 with package 628-545ffde)