config upload within firmware update page implemented

This commit is contained in:
DeltaLima 2025-04-07 16:51:03 +02:00
parent e11e807f54
commit 197b0691a4
6 changed files with 67 additions and 8 deletions

View file

@ -10,7 +10,7 @@
* DEBUG is less noisy messages
* DEBUG2 are noisy messages
* DEBUG3 are super noisy messages */
//#define DEBUG
#define DEBUG
//#define DEBUG2
//#define DEBUG3

View file

@ -42,7 +42,7 @@ byte Light_Power(byte id, unsigned int sunriseSec, unsigned int sunsetSec, unsig
//}
#ifdef DEBUG
#ifdef DEBUG2
Log.verbose(F("%s Light %d - power_tmp %d" CR), LogLoc, id, power_tmp);
#endif
return power_tmp;
@ -68,14 +68,14 @@ void Control_Light() {
if((config.grow.start < 1) || (now() - config.grow.start <= config.grow.daysVeg * 24 * 60 * 60)) {
sunriseSec = (config.grow.light.sunriseHourVeg[i] * 60 * 60) + (config.grow.light.sunriseMinuteVeg[i] * 60);
sunsetSec = (config.grow.light.sunsetHourVeg[i] * 60 * 60) + (config.grow.light.sunsetMinuteVeg[i] * 60);
#ifdef DEBUG
#ifdef DEBUG2
Log.verbose(F("%s Veg" CR), LogLoc);
#endif
/* now > than veg = bloom */
} else if(now() - config.grow.start > config.grow.daysVeg * 24 * 60 * 60) {
sunriseSec = (config.grow.light.sunriseHourBloom[i] * 60 * 60) + (config.grow.light.sunriseMinuteBloom[i] * 60);
sunsetSec = (config.grow.light.sunsetHourBloom[i] * 60 * 60) + (config.grow.light.sunsetMinuteBloom[i] * 60);
#ifdef DEBUG
#ifdef DEBUG2
Log.verbose(F("%s Bloom" CR), LogLoc);
#endif
/* now > than veg+bloom = harvest*/

View file

@ -55,6 +55,7 @@ void Webserver_Init() {
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/updateConfig", HTTP_POST, WebPage_system_updateConfig, WebPage_system_update_ApplyUpdateConfig);
webserver.on("/system/restart", HTTP_GET, WebPage_system_restart);
webserver.on("/system/restart", HTTP_POST, WebPage_system_restart);

View file

@ -976,14 +976,14 @@ String Proc_WebPage_grow_dashboard(const String& var) {
} else {
return String();
}
} else if(var == "ADD_DISABLED_SCHNUSEL") {
} else if(var == "ADD_DISABLED_DATA") {
if(Give_Free_Dashboard_ChartId() > Max_Dashboard_Chart ) {
return F("disabled force_hide");
} else {
return String();
}
}
* WTF CAUSES THIS BLOCK A CRASH??!?! When i delete the last one "ADD_DISABLED_SCHNUSEL", then it dont crash - LOLWTF?!
WTF CAUSES THIS BLOCK A CRASH??!?! When i delete the last one "ADD_DISABLED_SCHNUSEL", then it dont crash - LOLWTF?!
* OOM maybe? I cant read the exception atm
* :: [WiFi:Init]
:: [WiFi:Connect] connecting to SSID: MyFancyWifi

View file

@ -334,13 +334,15 @@ void WebPage_system_update_ApplyUpdate(AsyncWebServerRequest *request, String fi
Update.printError(Serial);
}
}
}
}
String Proc_WebPage_system_update(const String& var) {
if(TestHeaderFooter(var)) {
return AddHeaderFooter(var, 2);
} else if(Test_WebPage_system_SUBNAV(var)) {
return Proc_WebPage_system_SUBNAV(var, WEB_SYSTEM_SUBNAV_UPDATE);
} else if(var == "SAVE_MSG") {
return String(Common_HTML_SAVE_MSG);
} else {
return String();
}
@ -373,6 +375,52 @@ void WebPage_system_update(AsyncWebServerRequest *request) {
}
/* Config Update handling
* https://github.com/ESP32Async/ESPAsyncWebServer/blob/main/examples/Upload/Upload.ino */
void WebPage_system_update_ApplyUpdateConfig(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
const static char LogLoc[] PROGMEM = "[Webserver:system:update:ApplyUpdateConfig]";
Log.notice(F("%s Upload[%s]: start=%u, len=%u, final=%d" CR), LogLoc, filename.c_str(), index, len, final); //Serial.printf("Upload[%s]: start=%u, len=%u, final=%d\n", filename.c_str(), index, len, final);
if (!index) {
request->_tempFile = LittleFS.open(CANGROW_CFG, "w");
if (!request->_tempFile) {
Log.notice(F("%s Upload[%s]: File not available for writing" CR), LogLoc, filename.c_str());
request->send(400, "text/plain", "File not available for writing");
}
}
if (len) {
request->_tempFile.write(data, len);
}
if (final) {
request->_tempFile.close();
}
}
void WebPage_system_updateConfig(AsyncWebServerRequest *request) {
if(request->method() == HTTP_POST) {
if (request->getResponse()) {
// 400 File not available for writing
return;
}
if (!LittleFS.exists(CANGROW_CFG)) {
return request->send(400, "text/plain", "Nothing uploaded");
}
// sends back the uploaded file
// request->send(LittleFS, CANGROW_CFG, "text/plain");
/* set needRestart to true and redirect to update page */
needRestart = true;
request->redirect(F("/system/update?success"));
} else {
request->send_P(200, TEXT_HTML, Page_system_update_HTML, Proc_WebPage_system_update);
}
}
/*******************************************************************************
* Subpage wipe
*/

View file

@ -67,16 +67,26 @@ const char Page_system_HTML[] PROGMEM = R"(%HEADER%
const char Page_system_update_HTML[] PROGMEM = R"(%HEADER%
%SUBNAV%
%SAVE_MSG%
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>
<div id='divUploading' style='display: none;' class='warnmsg'>&#x1F6DC; Uploading, please wait...</div>
<h3>Firmware</h3>
<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'>&#x1F6DC; Uploading, please wait...</div>
<h3>Config</h3>
<form method='POST' action='/system/updateConfig' enctype='multipart/form-data' onsubmit="document.getElementById('divUploading').style.display = '';">
<b>Select config.json file:</b><br>
<input type='file' accept='.json' name='config' required>
<input type='submit' value='Update Config'>
</form>
%FOOTER% )";