Skip to content

Commit

Permalink
Add setClientTimeout() to ESP8266HTTPUpdate (esp8266#8740)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DarioGHub authored and hasenradball committed Nov 18, 2024
1 parent f5440b1 commit a7411d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 2 additions & 8 deletions libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ ESP8266WiFiMulti WiFiMulti;
void setup() {

Serial.begin(115200);
// Serial.setDebugOutput(true);
// Serial.setDebugOutput(false);

Serial.println();
Serial.println();
Serial.println();

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

WiFi.mode(WIFI_STA);
WiFiMulti.addAP(APSSID, APPSK);
Expand Down
3 changes: 3 additions & 0 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class ESP8266HTTPUpdate
int getLastError(void);
String getLastErrorString(void);

void setClientTimeout(int timeout) {
_httpClientTimeout = timeout;
}
protected:
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false);
bool runUpdate(Stream& in, uint32_t size, const String& md5, int command = U_FLASH);
Expand Down

0 comments on commit a7411d7

Please sign in to comment.