Skip to content

Commit 9701d3a

Browse files
authored
Add setClientTimeout() to ESP8266HTTPUpdate (#8740)
Shortening up the default hard-coded 8000 ms timeout, will save energy when module can't reach its update server, especially on battery powered projects, and otherwise provide adaptability to the local wlan. The ESPhttpUpdate object is auto-created by #including ESP8266HTTPUpdate. ESP8266HTTPUpdate also provides a constructor with param httpClientTimeout, but to use it required destroying the auto ESPhttpUpdate object, or creating a secondESPhttpUpdate(timeout) object.
1 parent 3c6db4e commit 9701d3a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ ESP8266WiFiMulti WiFiMulti;
2323
void setup() {
2424

2525
Serial.begin(115200);
26-
// Serial.setDebugOutput(true);
26+
// Serial.setDebugOutput(false);
2727

28-
Serial.println();
29-
Serial.println();
3028
Serial.println();
3129

32-
for (uint8_t t = 4; t > 0; t--) {
33-
Serial.printf("[SETUP] WAIT %d...\n", t);
34-
Serial.flush();
35-
delay(1000);
36-
}
30+
ESPhttpUpdate.setClientTimeout(2000); // default was 8000
3731

3832
WiFi.mode(WIFI_STA);
3933
WiFiMulti.addAP(APSSID, APPSK);

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class ESP8266HTTPUpdate
130130
int getLastError(void);
131131
String getLastErrorString(void);
132132

133+
void setClientTimeout(int timeout) {
134+
_httpClientTimeout = timeout;
135+
}
133136
protected:
134137
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false);
135138
bool runUpdate(Stream& in, uint32_t size, const String& md5, int command = U_FLASH);

0 commit comments

Comments
 (0)