ESP.RGBWiFi: Added timeout

This commit is contained in:
Nis Wechselberg 2017-02-17 23:31:10 +01:00
parent c033b60c1b
commit 045f7bcad2

View file

@ -115,11 +115,16 @@ void loop() {
WiFiClient client = server.available(); WiFiClient client = server.available();
if (client) { if (client) {
// Wait until the client sends some data // Wait until the client sends some data
Serial.println("Client connected"); Serial.print("Client connected");
while(!client.available()){ unsigned char timeouts = 10;
delay(1); while(!client.available() && timeouts > 0){
delay(10);
timeouts -= 1;
Serial.print(".");
} }
Serial.println("");
if (timeouts > 0) {
// Read the first line of the request // Read the first line of the request
String req = client.readStringUntil('\r'); String req = client.readStringUntil('\r');
Serial.println(req); Serial.println(req);
@ -202,6 +207,8 @@ void loop() {
// Send the response to the client // Send the response to the client
client.print(response); client.print(response);
delay(1); delay(1);
}
client.flush(); client.flush();
Serial.println("Disconnecting client"); Serial.println("Disconnecting client");
// The client will actually be disconnected // The client will actually be disconnected