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

new OTA page with progressbar #1756

Merged
merged 21 commits into from
Jan 7, 2023
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 💡 Feature Request
description: Use this form if you have an idea or wish for a new feature
labels: feature
labels: enhancement
body:


Expand Down
3 changes: 2 additions & 1 deletion code/components/jomjol_controlcamera/ClassControllCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ void CCamera::useDemoMode()

FILE *fd = fopen("/sdcard/demo/files.txt", "r");
if (!fd) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Please provide the demo files first!");
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can not start Demo mode, the folder '/sdcard/demo/' does not contain the needed files!");
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "See Details on https://github.com/jomjol/AI-on-the-edge-device/wiki/Demo-Mode!");
return;
}

Expand Down
24 changes: 24 additions & 0 deletions code/components/jomjol_fileserver_ota/server_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ static const char *TAG = "SERVER HELP";

char scratch[SERVER_HELPER_SCRATCH_BUFSIZE];


bool endsWith(std::string const &str, std::string const &suffix) {
if (str.length() < suffix.length()) {
return false;
}
return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
}


esp_err_t send_file(httpd_req_t *req, std::string filename)
{
FILE *fd = fopen(filename.c_str(), "r");
Expand All @@ -40,6 +49,21 @@ esp_err_t send_file(httpd_req_t *req, std::string filename)

ESP_LOGD(TAG, "Sending file: %s ...", filename.c_str());
// httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");

/* For all files with the following file extention tell
the webbrowser to cache them for 24h */
if (endsWith(filename, ".html") ||
endsWith(filename, ".htm") ||
endsWith(filename, ".css") ||
endsWith(filename, ".js") ||
endsWith(filename, ".map") ||
endsWith(filename, ".jpg") ||
endsWith(filename, ".jpeg") ||
endsWith(filename, ".ico") ||
endsWith(filename, ".png")) {
httpd_resp_set_hdr(req, "Cache-Control", "max-age=86400");
}

set_content_type_from_file(req, filename.c_str());

/* Retrieve the pointer to scratch buffer for temporary storage */
Expand Down
69 changes: 12 additions & 57 deletions code/components/jomjol_fileserver_ota/server_ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ void task_do_Update_ZIP(void *pvParameter)
ota_update_task(retfirmware);
}

if (initial_setup)
{

}

LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update.");
doRebootOTA();
} else if (filetype == "BIN")
{
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Do firmware update - file: " + _file_name_update);
ota_update_task(_file_name_update);
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Trigger reboot due to firmware update.");
doRebootOTA();
}
Expand Down Expand Up @@ -443,7 +444,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
}


if (filetype == "ZIP")
if ((filetype == "ZIP") || (filetype == "BIN"))
{
FILE *pfile;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Update for reboot.");
Expand All @@ -457,32 +458,9 @@ esp_err_t handler_ota_update(httpd_req_t *req)
ESP_LOGD(TAG, "Send reboot");
return ESP_OK;



/*
std::string in, out, outbin, zw, retfirmware;

out = "/sdcard/html";
outbin = "/sdcard/firmware";

retfirmware = unzip_new(fn, out+"/", outbin+"/");

if (retfirmware.length() > 0)
{
filetype = "BIN";
fn = retfirmware;
}
else
{
zw = "Web Interface Update Successfull!\nNo reboot necessary.\n";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
*/
}


/*
if (filetype == "BIN")
{
const char* resp_str;
Expand All @@ -507,7 +485,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)

return ESP_OK;
}

*/

std::string zw = "Update failed - no valid file specified (zip, bin, tfl, tlite)!";
httpd_resp_sendstr_chunk(req, zw.c_str());
Expand Down Expand Up @@ -667,40 +645,17 @@ esp_err_t handler_reboot(httpd_req_t *req)
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot");
ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!");

char _query[200];
char _valuechar[30];
std::string _task;
std::string response =
"<html><head><script>"
"function m(h) {"
"document.getElementById('t').innerHTML=h;"
"setInterval(function (){h +='.'; document.getElementById('t').innerHTML=h;"
"fetch('reboot_page.html',{mode: 'no-cors'}).then(r=>{parent.location.href=('index.html');})}, 1000);"
"}</script></head></html><body style='font-family: arial'><h3 id=t></h3>";

if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
ESP_LOGD(TAG, "Query: %s", _query);

if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
ESP_LOGD(TAG, "task is found: %s", _valuechar);
_task = std::string(_valuechar);
}
}
"}</script></head></html><body style='font-family: arial'><h3 id=t></h3>"
"<script>m('Rebooting!<br>The page will automatically reload in around 25..60s.<br><br>');</script>"
"</body></html>";

httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");

if (_task.compare("OTA") == 0) { // Reboot after OTA upload
response.append("<script>m('The upload completed successfully.<br>Rebooting and installing it now...<br><br>"
"The page will automatically reload after the update completed.<br>"
"This can take several minutes!<br><br>');</script>");
}
else { // Normal reboot
response.append("<script>m('Rebooting!<br>The page will automatically reload in around 25..60s.<br><br>');</script>");
}

response.append("</body></html>");
httpd_resp_send(req, response.c_str(), strlen(response.c_str()));

doReboot();
Expand Down
4 changes: 2 additions & 2 deletions code/components/jomjol_tfliteclass/server_tflite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,11 +839,11 @@ void task_autodoFlow(void *pvParameter)
if (!isPlannedReboot)
{
if (esp_reset_reason() == ESP_RST_PANIC) {
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Restarted due to an Exception/panic! Postponing first round start by 5 minutes to allow for an OTA or to fetch the log!");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Restarted due to an Exception/panic! Postponing first round start by 5 minutes to allow for an OTA Update or to fetch the log!");
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Setting logfile level to DEBUG until the next reboot!");
LogFile.setLogLevel(ESP_LOG_DEBUG);
//MQTTPublish(GetMQTTMainTopic() + "/" + "status", "Postponing first round", false);
vTaskDelay(60*5000 / portTICK_RATE_MS); // Wait 5 minutes to give time to do an OTA or fetch the log
vTaskDelay(60*5000 / portTICK_RATE_MS); // Wait 5 minutes to give time to do an OTA Update or fetch the log
}
}

Expand Down
4 changes: 4 additions & 0 deletions sd-card/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<script type="text/javascript" src="readconfigcommon.js"></script>
<script type="text/javascript" src="readconfigparam.js"></script>

<script type="text/javascript" src="jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="firework.js"></script>

<script>
async function loadPage(page) {
console.log("loadPage(" + page + ")");
Expand Down
Loading