Skip to content

Commit

Permalink
[Provisioning] Show error and event on failed firmware update (letsco…
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Jan 17, 2024
1 parent f665a17 commit 5dc2def
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
15 changes: 15 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ To create/register a plugin, you have to :
#ifdef FEATURE_CUSTOM_PROVISIONING
#undef FEATURE_CUSTOM_PROVISIONING
#endif
// FIXME TD-er: Should this be enabled on non-Custom builds???
#define FEATURE_CUSTOM_PROVISIONING 1


Expand Down Expand Up @@ -3291,6 +3292,20 @@ To create/register a plugin, you have to :
#endif


// Enable dependencies for custom provisioning
// FIXME TD-er: What about using this feature on non-Custom builds????
#if FEATURE_CUSTOM_PROVISIONING
#ifdef FEATURE_DOWNLOAD
#undef FEATURE_DOWNLOAD
#endif
#define FEATURE_DOWNLOAD 1
#ifdef FEATURE_SETTINGS_ARCHIVE
#undef FEATURE_SETTINGS_ARCHIVE
#endif
#define FEATURE_SETTINGS_ARCHIVE 1
#endif



// TODO TD-er: Test feature, must remove
/*
Expand Down
68 changes: 39 additions & 29 deletions src/src/Helpers/Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String
{
WiFiClient client;
HTTPClient http;
error.clear();

if (!start_downloadFile(client, http, url, file_save, user, pass, error)) {
return false;
Expand All @@ -1818,7 +1819,7 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String
// get tcp stream
WiFiClient *stream = &client;

while (http.connected() && (len > 0 || len == -1)) {
while (error.isEmpty() && http.connected() && (len > 0 || len == -1)) {
// read up to downloadBuffSize at a time.
size_t bytes_to_read = downloadBuffSize;

Expand All @@ -1833,11 +1834,7 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String
if (Update.write(buff, c) != c) {
error = strformat(F("Error saving firmware update: %s %d Bytes written"),
file_save.c_str(), bytesWritten);
addLog(LOG_LEVEL_ERROR, error);
Update.end();
http.end();
client.stop();
return false;
break;
}
bytesWritten += c;

Expand All @@ -1846,12 +1843,7 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String

if (timeOutReached(timeout)) {
error = concat(F("Timeout: "), file_save);
addLog(LOG_LEVEL_ERROR, error);
delay(0);
Update.end();
http.end();
client.stop();
return false;
break;
}

if (!UseRTOSMultitasking) {
Expand All @@ -1860,30 +1852,48 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String
}
backgroundtasks();
}
http.end();
client.stop();
}
http.end();
client.stop();

if (loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
if (error.isEmpty() && loglevelActiveFor(LOG_LEVEL_INFO)) {
addLog(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
}

uint8_t errorcode = 0;
if (!Update.end()) {
errorcode = Update.getError();
const __FlashStringHelper * err_fstr = F("Unknown");
switch (errorcode) {
case UPDATE_ERROR_OK: err_fstr = F("OK"); break;
case UPDATE_ERROR_WRITE: err_fstr = F("WRITE"); break;
case UPDATE_ERROR_ERASE: err_fstr = F("ERASE"); break;
case UPDATE_ERROR_READ: err_fstr = F("READ"); break;
case UPDATE_ERROR_SPACE: err_fstr = F("SPACE"); break;
case UPDATE_ERROR_SIZE: err_fstr = F("SIZE"); break;
case UPDATE_ERROR_STREAM: err_fstr = F("STREAM"); break;
case UPDATE_ERROR_MD5: err_fstr = F("MD5"); break;
case UPDATE_ERROR_MAGIC_BYTE: err_fstr = F("MAGIC_BYTE"); break;
case UPDATE_ERROR_ACTIVATE: err_fstr = F("ACTIVATE"); break;
case UPDATE_ERROR_NO_PARTITION: err_fstr = F("NO_PARTITION"); break;
case UPDATE_ERROR_BAD_ARGUMENT: err_fstr = F("BAD_ARGUMENT"); break;
case UPDATE_ERROR_ABORT: err_fstr = F("ABORT"); break;
}

if (Update.end()) {
if (Settings.UseRules) {
eventQueue.addMove(concat(F("ProvisionFirmware#success="), file_save));
}
error += concat(F(" Error: "), err_fstr);
} else {
if (Settings.UseRules) {
eventQueue.addMove(concat(F("ProvisionFirmware#success="), file_save));
}
return true;
}
http.end();
client.stop();
Update.end();
error = concat(F("Failed update firmware: "), file_save);
addLog(LOG_LEVEL_ERROR, error);

backgroundtasks();
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
addLog(LOG_LEVEL_ERROR, concat(F("Failed update firmware: "), error));
}

if (Settings.UseRules) {
String event = F("ProvisionFirmware#failed=");
event += file_save;
eventQueue.addMove(std::move(event));
eventQueue.addMove(concat(F("ProvisionFirmware#failed="), file_save));
}
return false;
}
Expand Down

0 comments on commit 5dc2def

Please sign in to comment.