diff --git a/examples/PlaneSpotterDemo/AdsbExchangeClient.cpp b/examples/PlaneSpotterDemo/AdsbExchangeClient.cpp index c382e72..e859707 100644 --- a/examples/PlaneSpotterDemo/AdsbExchangeClient.cpp +++ b/examples/PlaneSpotterDemo/AdsbExchangeClient.cpp @@ -42,11 +42,9 @@ void AdsbExchangeClient::updateVisibleAircraft(String searchQuery) { int pos = 0; boolean isBody = false; char c; - - int size = 0; client.setNoDelay(false); - while(client.available() || client.connected()) { - while((size = client.available()) > 0) { + while (client.available() || client.connected()) { + while (client.available()) { c = client.read(); if (c == '{' || c == '[') { isBody = true; @@ -55,6 +53,7 @@ void AdsbExchangeClient::updateVisibleAircraft(String searchQuery) { parser.parse(c); } } + client.stop(); } endDocument(); } diff --git a/src/AerisForecasts.cpp b/src/AerisForecasts.cpp index 1b2c5de..44e259b 100644 --- a/src/AerisForecasts.cpp +++ b/src/AerisForecasts.cpp @@ -49,7 +49,6 @@ void AerisForecasts::doUpdate(AerisForecastData *forecasts, String url, uint8_t http.begin(url); bool isBody = false; char c; - int size; Serial.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); @@ -58,13 +57,13 @@ void AerisForecasts::doUpdate(AerisForecastData *forecasts, String url, uint8_t WiFiClient * client = http.getStreamPtr(); - while(client->available() || client->connected()) { - while((size = client->available()) > 0) { - if ((millis() - lost_do) > lostTest) { - Serial.println ("lost in client with a timeout"); - client->stop(); - ESP.restart(); - } + while (client->available() || client->connected()) { + while (client->available()) { + if ((millis() - lost_do) > lostTest) { + Serial.println("lost in client with a timeout"); + client->stop(); + ESP.restart(); + } c = client->read(); if (c == '{' || c == '[') { @@ -74,6 +73,7 @@ void AerisForecasts::doUpdate(AerisForecastData *forecasts, String url, uint8_t parser.parse(c); } } + client->stop(); } } this->forecasts = nullptr; diff --git a/src/AerisObservations.cpp b/src/AerisObservations.cpp index 02b9439..21a49b8 100644 --- a/src/AerisObservations.cpp +++ b/src/AerisObservations.cpp @@ -56,13 +56,13 @@ void AerisObservations::doUpdate(AerisObservationsData *observations, String url WiFiClient * client = http.getStreamPtr(); - while(client->available() || client->connected()) { - while((size = client->available()) > 0) { - if ((millis() - lost_do) > lostTest) { - Serial.println ("lost in client with a timeout"); - client->stop(); - ESP.restart(); - } + while (client->available() || client->connected()) { + while (client->available()) { + if ((millis() - lost_do) > lostTest) { + Serial.println("lost in client with a timeout"); + client->stop(); + ESP.restart(); + } c = client->read(); if (c == '{' || c == '[') { @@ -72,6 +72,7 @@ void AerisObservations::doUpdate(AerisObservationsData *observations, String url parser.parse(c); } } + client->stop(); } } this->observations = nullptr; diff --git a/src/AerisSunMoon.cpp b/src/AerisSunMoon.cpp index fb9fad6..1d4facb 100644 --- a/src/AerisSunMoon.cpp +++ b/src/AerisSunMoon.cpp @@ -48,7 +48,6 @@ void AerisSunMoon::doUpdate(AerisSunMoonData *sunMoonData, String url) { http.begin(url); bool isBody = false; char c; - int size; Serial.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); @@ -57,13 +56,13 @@ void AerisSunMoon::doUpdate(AerisSunMoonData *sunMoonData, String url) { WiFiClient * client = http.getStreamPtr(); - while(client->available() || client->connected()) { - while((size = client->available()) > 0) { - if ((millis() - lost_do) > lostTest) { - Serial.println ("lost in client with a timeout"); - client->stop(); - ESP.restart(); - } + while (client->available() || client->connected()) { + while (client->available()) { + if ((millis() - lost_do) > lostTest) { + Serial.println("lost in client with a timeout"); + client->stop(); + ESP.restart(); + } c = client->read(); if (c == '{' || c == '[') { @@ -73,6 +72,7 @@ void AerisSunMoon::doUpdate(AerisSunMoonData *sunMoonData, String url) { parser.parse(c); } } + client->stop(); } } this->sunMoonData = nullptr; diff --git a/src/MetOfficeClient.cpp b/src/MetOfficeClient.cpp index 61531d4..ab47da4 100644 --- a/src/MetOfficeClient.cpp +++ b/src/MetOfficeClient.cpp @@ -96,10 +96,9 @@ void MetOfficeClient::doUpdate(String url) { boolean isBody = false; char c; - int size = 0; client.setNoDelay(false); - while(client.connected()) { - while((size = client.available()) > 0) { + while (client.connected()) { + while (client.available()) { c = client.read(); if (c == '{' || c == '[') { isBody = true; @@ -108,6 +107,7 @@ void MetOfficeClient::doUpdate(String url) { parser.parse(c); } } + client.stop(); } } diff --git a/src/OpenWeatherMapCurrent.cpp b/src/OpenWeatherMapCurrent.cpp index d195397..1bb45c2 100644 --- a/src/OpenWeatherMapCurrent.cpp +++ b/src/OpenWeatherMapCurrent.cpp @@ -56,7 +56,6 @@ void OpenWeatherMapCurrent::doUpdate(OpenWeatherMapCurrentData *data, String url http.begin(url); bool isBody = false; char c; - int size; Serial.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); @@ -65,16 +64,15 @@ void OpenWeatherMapCurrent::doUpdate(OpenWeatherMapCurrentData *data, String url WiFiClient * client = http.getStreamPtr(); - while(client->connected() || client->available()) { - while((size = client->available()) > 0) { - if ((millis() - lost_do) > lostTest) { - Serial.println ("lost in client with a timeout"); - client->stop(); - ESP.restart(); - } + while (client->connected() || client->available()) { + while (client->available()) { + if ((millis() - lost_do) > lostTest) { + Serial.println("lost in client with a timeout"); + client->stop(); + ESP.restart(); + } c = client->read(); if (c == '{' || c == '[') { - isBody = true; } if (isBody) { @@ -83,6 +81,7 @@ void OpenWeatherMapCurrent::doUpdate(OpenWeatherMapCurrentData *data, String url // give WiFi and TCP/IP libraries a chance to handle pending events yield(); } + client->stop(); } } this->data = nullptr; diff --git a/src/OpenWeatherMapForecast.cpp b/src/OpenWeatherMapForecast.cpp index 7cd39f7..7a9d5fe 100644 --- a/src/OpenWeatherMapForecast.cpp +++ b/src/OpenWeatherMapForecast.cpp @@ -59,7 +59,6 @@ uint8_t OpenWeatherMapForecast::doUpdate(OpenWeatherMapForecastData *data, Strin http.begin(url); bool isBody = false; char c; - int size; Serial.print("[HTTP] GET...\n"); // start connection and send HTTP header int httpCode = http.GET(); @@ -68,16 +67,15 @@ uint8_t OpenWeatherMapForecast::doUpdate(OpenWeatherMapForecastData *data, Strin WiFiClient * client = http.getStreamPtr(); - while(client->connected() || client->available()) { - while((size = client->available()) > 0) { - if ((millis() - lost_do) > lostTest) { - Serial.println ("lost in client with a timeout"); - client->stop(); - ESP.restart(); - } + while (client->connected() || client->available()) { + while (client->available()) { + if ((millis() - lost_do) > lostTest) { + Serial.println("lost in client with a timeout"); + client->stop(); + ESP.restart(); + } c = client->read(); if (c == '{' || c == '[') { - isBody = true; } if (isBody) { @@ -86,6 +84,7 @@ uint8_t OpenWeatherMapForecast::doUpdate(OpenWeatherMapForecastData *data, Strin // give WiFi and TCP/IP libraries a chance to handle pending events yield(); } + client->stop(); } } this->data = nullptr; diff --git a/src/ThingspeakClient.cpp b/src/ThingspeakClient.cpp index 3ff4bf8..3a954df 100644 --- a/src/ThingspeakClient.cpp +++ b/src/ThingspeakClient.cpp @@ -43,10 +43,9 @@ void ThingspeakClient::getLastChannelItem(String channelId, String readApiKey) { boolean isBody = false; char c; - int size = 0; client.setNoDelay(false); - while(client.available() || client.connected()) { - while((size = client.available()) > 0) { + while (client.available() || client.connected()) { + while (client.available()) { c = client.read(); if (c == '{' || c == '[') { isBody = true; @@ -55,6 +54,7 @@ void ThingspeakClient::getLastChannelItem(String channelId, String readApiKey) { parser.parse(c); } } + client.stop(); } } diff --git a/src/TimeClient.cpp b/src/TimeClient.cpp index f482e15..840f934 100644 --- a/src/TimeClient.cpp +++ b/src/TimeClient.cpp @@ -53,17 +53,15 @@ void TimeClient::updateTime() { } String line; - - int size = 0; client.setNoDelay(false); - while(client.available() || client.connected()) { - while((size = client.available()) > 0) { + while (client.available() || client.connected()) { + while (client.available()) { line = client.readStringUntil('\n'); line.toUpperCase(); // example: // date: Thu, 19 Nov 2015 20:25:40 GMT if (line.startsWith("DATE: ")) { - Serial.println(line.substring(23, 25) + ":" + line.substring(26, 28) + ":" +line.substring(29, 31)); + Serial.println(line.substring(23, 25) + ":" + line.substring(26, 28) + ":" + line.substring(29, 31)); int parsedHours = line.substring(23, 25).toInt(); int parsedMinutes = line.substring(26, 28).toInt(); int parsedSeconds = line.substring(29, 31).toInt(); @@ -74,8 +72,8 @@ void TimeClient::updateTime() { localMillisAtUpdate = millis(); } } + client.stop(); } - } String TimeClient::getHours() { diff --git a/src/WorldClockClient.cpp b/src/WorldClockClient.cpp index 507ee88..a82d9a7 100644 --- a/src/WorldClockClient.cpp +++ b/src/WorldClockClient.cpp @@ -90,11 +90,9 @@ void WorldClockClient::updateTime() { int pos = 0; boolean isBody = false; char c; - - int size = 0; client.setNoDelay(false); - while(client.available() || client.connected()) { - while((size = client.available()) > 0) { + while (client.available() || client.connected()) { + while (client.available()) { c = client.read(); if (c == '{' || c == '[') { isBody = true; @@ -103,6 +101,7 @@ void WorldClockClient::updateTime() { parser.parse(c); } } + client.stop(); } }