web firmware update implemented
This commit is contained in:
parent
f093ac843b
commit
e7bb42f72b
4 changed files with 70 additions and 3 deletions
|
@ -44,8 +44,9 @@
|
|||
#define CANGROW_SSID "CanGrow-unconfigured"
|
||||
|
||||
// do we need a restart? (e.g. after wifi settings change)
|
||||
bool needRestart;
|
||||
bool doRestart;
|
||||
bool needRestart = false;
|
||||
// this triggers Restart() from the main loop
|
||||
bool doRestart = false;
|
||||
// previous value of millis within the scheduler loop
|
||||
unsigned long schedulerPrevMillis = 0;
|
||||
|
||||
|
|
|
@ -89,6 +89,10 @@ void Webserver_Init() {
|
|||
webserver.on("/wifi/", HTTP_POST, WebPage_wifi);
|
||||
webserver.on("/system/", HTTP_GET, WebPage_system);
|
||||
webserver.on("/system/", HTTP_POST, WebPage_system);
|
||||
|
||||
webserver.on("/system/update", HTTP_GET, WebPage_system_update);
|
||||
webserver.on("/system/update", HTTP_POST, WebPage_system_update, WebPage_system_update_ApplyUpdate);
|
||||
|
||||
webserver.on("/system/restart", HTTP_GET, WebPage_system_restart);
|
||||
webserver.on("/system/restart", HTTP_POST, WebPage_system_restart);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void WebPage_system(AsyncWebServerRequest *request) {
|
|||
|
||||
|
||||
/*
|
||||
* Page subpage restart
|
||||
* Subpage restart
|
||||
*/
|
||||
String Proc_WebPage_system_restart(const String& var) {
|
||||
if(TestHeaderFooter(var)) {
|
||||
|
@ -84,3 +84,44 @@ void WebPage_system_restart(AsyncWebServerRequest *request) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Subpage update
|
||||
*/
|
||||
|
||||
void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
|
||||
if(!index){
|
||||
Serial.printf("Update Start: %s\n", filename.c_str());
|
||||
Update.runAsync(true);
|
||||
if(!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)){
|
||||
Update.printError(Serial);
|
||||
}
|
||||
}
|
||||
if(!Update.hasError()){
|
||||
if(Update.write(data, len) != len){
|
||||
Update.printError(Serial);
|
||||
}
|
||||
}
|
||||
if(final){
|
||||
if(Update.end(true)){
|
||||
Serial.printf("Update Success: %uB\n", index+len);
|
||||
} else {
|
||||
Update.printError(Serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebPage_system_update(AsyncWebServerRequest *request) {
|
||||
if(request->method() == HTTP_POST) {
|
||||
needRestart = !Update.hasError();
|
||||
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", needRestart?"OK":"FAIL");
|
||||
response->addHeader("Connection", "close");
|
||||
request->send(response);
|
||||
} else {
|
||||
request->send_P(200, "text/html", Page_system_update_HTML, AddHeaderFooter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -74,6 +74,27 @@ ESP32-Cam IP (optional): <input type='text' name='Esp32CamIP' maxlength='16' val
|
|||
%FOOTER%)";
|
||||
|
||||
|
||||
/*
|
||||
* Subpage update
|
||||
*/
|
||||
const char* Page_system_update_HTML PROGMEM = R"(%HEADER%
|
||||
<h2>🔄 Firmware update</h2>
|
||||
Version: %CGVER% <br>
|
||||
Build : %CGBUILD% <br>
|
||||
|
||||
<p>You find the latest CanGrow firmware version on the <a href='https://git.la10cy.net/DeltaLima/CanGrow/releases' target='_blank'>release page</a> of the git repository.</p>
|
||||
<form method='POST' action='/system/update' enctype='multipart/form-data' onsubmit="document.getElementById('divUploading').style.display = '';">
|
||||
<b>Select .bin file:</b><br>
|
||||
<input type='file' accept='.bin,.bin.gz' name='firmware' required>
|
||||
<input type='submit' value='Update Firmware'>
|
||||
</form>
|
||||
<div id='divUploading' style='display: none;' class='warnmsg'>🛜 Uploading, please wait...<div>
|
||||
|
||||
%FOOTER%)";
|
||||
|
||||
/*
|
||||
* Subpage restart
|
||||
*/
|
||||
const char* Page_system_restart_HTML PROGMEM = R"(%HEADER%
|
||||
<h1>❗ Restart CanGrow</h1>
|
||||
<div class='warnmsg'>
|
||||
|
|
Loading…
Reference in a new issue