Skip to content

Add a start callback for HTTP updater #1817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

ESP8266WiFiMulti WiFiMulti;

void update_starting(void) {
Serial.println("Update starting");
}

void setup() {

USE_SERIAL.begin(115200);
Expand All @@ -40,6 +44,7 @@ void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {

ESPhttpUpdate.onStart(update_starting);
t_httpUpdate_return ret = ESPhttpUpdate.update("http://server/file.bin");
//t_httpUpdate_return ret = ESPhttpUpdate.update("https://server/file.bin");

Expand Down
3 changes: 1 addition & 2 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
// track these headers
http->collectHeaders(headerkeys, headerkeyssize);


int code = http->GET();
int len = http->getSize();

Expand Down Expand Up @@ -223,7 +222,7 @@ t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const cha
lastError = HTTP_UE_TOO_LESS_SPACE;
ret = HTTP_UPDATE_FAILED;
} else {

http_update_start();
WiFiClient * tcp = http->getStreamPtr();

WiFiUDP::stopAll();
Expand Down
4 changes: 4 additions & 0 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)

#define HTTP_UPDATE_START_CALLBACK(callback) void (*callback)()

typedef enum {
HTTP_UPDATE_FAILED,
HTTP_UPDATE_NO_UPDATES,
Expand All @@ -71,12 +73,14 @@ class ESP8266HTTPUpdate {

int getLastError(void);
String getLastErrorString(void);
void onStart(HTTP_UPDATE_START_CALLBACK(callback)) { http_update_start = callback; }

protected:
t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version, bool reboot = true, bool spiffs = false);
bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH);

int lastError;
HTTP_UPDATE_START_CALLBACK(http_update_start);
};

extern ESP8266HTTPUpdate ESPhttpUpdate;
Expand Down