From 81859c5df63549e39b3840713e76596ab523fdec Mon Sep 17 00:00:00 2001 From: Hemal Chevli Date: Tue, 5 Apr 2016 10:53:15 +0530 Subject: [PATCH 1/2] Changed timeout logic Changed timeout to unsigned long. Using addition with millis() is not recommended. Source: http://www.gammon.com.au/millis --- libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index eb7c02eff..7129e474c 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -71,9 +71,9 @@ void loop() { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); - int timeout = millis() + 5000; + unsigned long timeout = millis(); while (client.available() == 0) { - if (timeout - millis() < 0) { + if (millis() - timeout < 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return; From e4e182a9667f89e9dbe5aef77ca56223efb9d0e8 Mon Sep 17 00:00:00 2001 From: Hemal Chevli Date: Tue, 5 Apr 2016 13:12:22 +0530 Subject: [PATCH 2/2] Rectified mistake in if condition thanks to @chaeplin for finding the mistake --- libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino index 7129e474c..4e3b78d5a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino +++ b/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino @@ -73,7 +73,7 @@ void loop() { "Connection: close\r\n\r\n"); unsigned long timeout = millis(); while (client.available() == 0) { - if (millis() - timeout < 5000) { + if (millis() - timeout > 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return;