Skip to content

Commit c4436d8

Browse files
committed
Merge pull request #1160 from martinayotte/master
replace delay() with a while loop in WiFiClient.ino
2 parents 1368a82 + e166e85 commit c4436d8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino

+8-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ void loop() {
7171
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
7272
"Host: " + host + "\r\n" +
7373
"Connection: close\r\n\r\n");
74-
delay(10);
74+
int timeout = millis() + 5000;
75+
while (client.available() == 0) {
76+
if (timeout - millis() < 0) {
77+
Serial.println(">>> Client Timeout !");
78+
client.stop();
79+
return;
80+
}
81+
}
7582

7683
// Read all the lines of the reply from server and print them to Serial
7784
while(client.available()){

0 commit comments

Comments
 (0)