From 20245911a1be7abd8420e3553ce8b105e46ef413 Mon Sep 17 00:00:00 2001 From: Marian Craciunescu Date: Thu, 3 May 2018 15:49:15 +0300 Subject: [PATCH 1/3] add http client configurable timeout usefull when download is slow from server side --- libraries/ESP8266httpUpdate/library.properties | 2 +- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 8 +++++++- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266httpUpdate/library.properties b/libraries/ESP8266httpUpdate/library.properties index 2116c04a05..94a8499b89 100644 --- a/libraries/ESP8266httpUpdate/library.properties +++ b/libraries/ESP8266httpUpdate/library.properties @@ -1,5 +1,5 @@ name=ESP8266httpUpdate -version=1.1 +version=1.2 author=Markus Sattler maintainer=Markus Sattler sentence=Http Update for ESP8266 diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index f08aa1edec..ff41df4133 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -31,6 +31,12 @@ extern "C" uint32_t _SPIFFS_end; ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) { + this->_http_client_timeout=8000; +} + +ESP8266HTTPUpdate::ESP8266HTTPUpdate(int httpClientTimeout) +{ + this->_http_client_timeout = httpClientTimeout; } ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) @@ -170,7 +176,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& // use HTTP/1.0 for update since the update handler not support any transfer Encoding http.useHTTP10(true); - http.setTimeout(8000); + http.setTimeout(this->_http_client_timeout); http.setUserAgent(F("ESP8266-http-Update")); http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress()); http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress()); diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index 0413f4656a..ee42ab81e1 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -64,6 +64,7 @@ class ESP8266HTTPUpdate { public: ESP8266HTTPUpdate(void); + ESP8266HTTPUpdate(int httpClientTimeout); ~ESP8266HTTPUpdate(void); void rebootOnUpdate(bool reboot) @@ -103,6 +104,8 @@ class ESP8266HTTPUpdate int _lastError; bool _rebootOnUpdate = true; +private: + int _http_client_timeout; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE) From 9954d6d25ecd0656a73de7288cb10c5014a1cf31 Mon Sep 17 00:00:00 2001 From: Marian Craciunescu Date: Fri, 4 May 2018 09:53:02 +0300 Subject: [PATCH 2/3] member init outside constructor body. --- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 6 +++--- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index ff41df4133..baf73a5447 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -30,13 +30,13 @@ extern "C" uint32_t _SPIFFS_start; extern "C" uint32_t _SPIFFS_end; ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) + : _httpClientTimeout(8000) { - this->_http_client_timeout=8000; } ESP8266HTTPUpdate::ESP8266HTTPUpdate(int httpClientTimeout) + : _httpClientTimeout(httpClientTimeout) { - this->_http_client_timeout = httpClientTimeout; } ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) @@ -176,7 +176,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& // use HTTP/1.0 for update since the update handler not support any transfer Encoding http.useHTTP10(true); - http.setTimeout(this->_http_client_timeout); + http.setTimeout(this->_httpClientTimeout); http.setUserAgent(F("ESP8266-http-Update")); http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress()); http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress()); diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index ee42ab81e1..ec532c2909 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -105,7 +105,7 @@ class ESP8266HTTPUpdate int _lastError; bool _rebootOnUpdate = true; private: - int _http_client_timeout; + int _httpClientTimeout; }; #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE) From faacaa7eff32f051837feda6309e767f8e115116 Mon Sep 17 00:00:00 2001 From: Marian Craciunescu Date: Fri, 4 May 2018 14:46:15 +0300 Subject: [PATCH 3/3] removed this. --- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index baf73a5447..92f1bfd85b 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -176,7 +176,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& // use HTTP/1.0 for update since the update handler not support any transfer Encoding http.useHTTP10(true); - http.setTimeout(this->_httpClientTimeout); + http.setTimeout(_httpClientTimeout); http.setUserAgent(F("ESP8266-http-Update")); http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress()); http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());