Skip to content
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

Wifi update fixes #32

Merged
merged 4 commits into from
Dec 14, 2021
Merged
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
37 changes: 26 additions & 11 deletions html/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,26 @@ function completeHandler(type_suffix) {
_("progressBar_" + type_suffix).value = 0;
var data = JSON.parse(event.target.responseText);
if (data.status === 'ok') {
cuteAlert({
type: 'success',
title: "Update Succeeded",
message: data.msg
});
function show_message() {
cuteAlert({
type: 'success',
title: "Update Succeeded",
message: data.msg
});
}
// This is basically a delayed display of the success dialog with a fake progress
var percent = 0;
var interval = setInterval(()=>{
percent = percent + 1;
_("progressBar_" + type_suffix).value = percent;
_("status_" + type_suffix).innerHTML = percent + "% flashed... please wait";
if (percent == 100) {
clearInterval(interval);
_("status_" + type_suffix).innerHTML = "";
_("progressBar_" + type_suffix).value = 0;
show_message();
}
}, 100);
} else if (data.status === 'mismatch') {
cuteAlert({
type: 'question',
Expand Down Expand Up @@ -257,9 +272,9 @@ function errorHandler(type_suffix) {
_("status_" + type_suffix).innerHTML = "";
_("progressBar_" + type_suffix).value = 0;
cuteAlert({
type: "error",
title: "Update Failed",
message: event.target.responseText
type: "error",
title: "Update Failed",
message: event.target.responseText
});
}
}
Expand All @@ -269,9 +284,9 @@ function abortHandler(type_suffix) {
_("status_" + type_suffix).innerHTML = "";
_("progressBar_" + type_suffix).value = 0;
cuteAlert({
type: "info",
title: "Update Aborted",
message: event.target.responseText
type: "info",
title: "Update Aborted",
message: event.target.responseText
});
}
}
Expand Down
32 changes: 11 additions & 21 deletions lib/WIFI/devWIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static uint8_t target_pos = 0;
static String target_found;
static bool target_complete = false;
static bool force_update = false;
static bool do_flash = false;
static uint32_t totalSize;
static UpdateWrapper updater = UpdateWrapper();

Expand Down Expand Up @@ -290,7 +291,7 @@ static void WebUploadResponseHandler(AsyncWebServerRequest *request) {
response->addHeader("Connection", "close");
request->send(response);
request->client()->close();
rebootTime = millis() + 200;
do_flash = true;
} else {
String message = String("{\"status\": \"mismatch\", \"msg\": \"<b>Current target:</b> ") + (const char *)&target_name[4] + ".<br>";
if (target_found.length() != 0) {
Expand Down Expand Up @@ -369,31 +370,11 @@ static void WebUploadDataHandler(AsyncWebServerRequest *request, const String& f
totalSize += len;
}
}
if (final && !updater.hasError()) {
DBGVLN("finish");
if (target_seen) {
if (updater.end(true)) { //true to set the size to the current progress
DBGLN("Upload Success: %ubytes\nPlease wait for LED to turn on before disconnecting power", totalSize);
} else {
updater.printError(Serial);
}
} else {
#if defined(PLATFORM_ESP32)
updater->abort();
#endif
DBGLN("Wrong firmware uploaded, not %s, update aborted", &target_name[4]);
}
}
}

static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) {
target_seen = true;
if (request->arg("action").equals("confirm")) {
if (updater.end(true)) { //true to set the size to the current progress
DBGLN("Upload Success: %ubytes\nPlease wait for LED to turn on before disconnecting power", totalSize);
} else {
updater.printError(Serial);
}
WebUploadResponseHandler(request);
} else {
#if defined(PLATFORM_ESP32)
Expand Down Expand Up @@ -598,6 +579,15 @@ static void HandleWebUpdate()
// In AP mode, it doesn't seem to make a measurable difference, but does not hurt
if (!updater.isRunning())
delay(1);
if (do_flash) {
do_flash = false;
if (updater.end(true)) { //true to set the size to the current progress
DBGLN("Upload Success: %ubytes\nPlease wait for LED to turn on before disconnecting power", totalSize);
} else {
updater.printError(Serial);
}
rebootTime = millis() + 200;
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions lib/WIFI/stmUpdateClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "logging.h"

static const char *spiffs_firmware_filename = "firmware.bin";

void STMUpdateClass::setFilename(const String& filename)
{
this->filename = filename;
Expand All @@ -16,8 +18,8 @@ bool STMUpdateClass::begin(size_t size)
_error = UPDATE_ERROR_OK;

/* Remove old file */
if (SPIFFS.exists(filename.c_str()))
SPIFFS.remove(filename.c_str());
if (SPIFFS.exists(spiffs_firmware_filename))
SPIFFS.remove(spiffs_firmware_filename);

FSInfo fs_info;
if (SPIFFS.info(fs_info))
Expand All @@ -41,7 +43,7 @@ bool STMUpdateClass::begin(size_t size)
_error = UPDATE_ERROR_READ;
return false;
}
fsUploadFile = SPIFFS.open(filename.c_str(), "w"); // Open the file for writing in SPIFFS (create if it doesn't exist)
fsUploadFile = SPIFFS.open(spiffs_firmware_filename, "w"); // Open the file for writing in SPIFFS (create if it doesn't exist)
return true;
}

Expand All @@ -55,8 +57,8 @@ bool STMUpdateClass::end(bool evenIfRemaining)
fsUploadFile.close(); // Close the file again

_error = flashSTM32(BEGIN_ADDRESS);
if (SPIFFS.exists(filename.c_str()))
SPIFFS.remove(filename.c_str());
if (SPIFFS.exists(spiffs_firmware_filename))
SPIFFS.remove(spiffs_firmware_filename);
return !hasError();
}

Expand All @@ -78,9 +80,10 @@ void STMUpdateClass::printError(Print &out){
int8_t STMUpdateClass::flashSTM32(uint32_t flash_addr)
{
if (filename.endsWith(".elrs")) {
_errmsg = stk500_write_file(filename.c_str());
_errmsg = stk500_write_file(spiffs_firmware_filename);
reset_stm32_to_app_mode();
} else if (filename.endsWith(".bin")) {
_errmsg = esp8266_spiffs_write_file(filename.c_str(), flash_addr);
_errmsg = esp8266_spiffs_write_file(spiffs_firmware_filename, flash_addr);
}
Serial.begin(460800);
if (_errmsg != NULL)
Expand Down