Commit 82ea894f authored by 李延凯's avatar 李延凯

feat: 修改升级页面格式, 删除不必要代码

parent 10c9f727
......@@ -7,8 +7,8 @@
<title>应用程序更新</title>
<script>
window.addEventListener("DOMContentLoaded", (event) => {
/* 加载完成后直接触发下拉菜单的点击动作 */
document.getElementById("id_select_partition").dispatchEvent(new Event('click'));
/* 加载完成后禁用升级按钮 */
document.getElementById("id_button_ota_start").disabled = true;
});
</script>
</head>
......@@ -18,18 +18,9 @@
<h2>应用程序更新</h2>
<hr>
<!-- 返回首页超链接 -->
<a href="javascript:void(0);" onclick="index_page()" style="font-size: smaller;">[返回首页]</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<!-- 页面重置超链接 -->
<a href="javascript:void(0);" onclick="reset_page()" style="font-size: smaller;">[重置页面]</a><br><br>
<!-- 下拉菜单 -->
<label for="lable_partition">更新程序:</label>
<select id="id_select_partition" name="name_select_part" onclick="print_expect_file_name()">
<option selected value="0">-</option>
<option value="1">ESP32-D0WDR2-V3</option>
<option value="2">N32G031C8L7</option>
</select><br><br>
<!-- 选择文本按钮 -->
<label for="label_file">选择文件:</label>
<input id="id_input_file" type="file" accept=".bin" onchange="get_file_info()">
......@@ -53,22 +44,9 @@
<p id="id_p_ota_result"></p>
<script>
function index_page() {
window.location.href = "http://192.168.4.1/";
}
function reset_page() {
location.replace(location.href);
}
function print_expect_file_name() {
var select_partition = document.getElementById("id_select_partition").value;
document.getElementById("id_button_ota_start").disabled = true;
if (select_partition == "0") {
document.getElementById("id_input_file").disabled = true;
}
else {
document.getElementById("id_input_file").disabled = false;
}
}
function get_file_size(size) {
var unit = 1024.00;
if (size < unit) {
......@@ -82,58 +60,30 @@
}
}
function get_file_info() {
var select_partition = document.getElementById("id_select_partition").value;
var select_file = document.getElementById("id_input_file").files[0];
var select_file_name = select_file.name;
var select_file_size = select_file.size;
var app_size;
var show_info;
var app_size = 2048 * 1024;
if (select_partition == "1") {
app_size = 3072 * 1024;
show_info = 1;
if (select_file_size > app_size) {
document.getElementById("id_p_ota_result").innerHTML = "超出最大限制(" + app_size / 1024 + "KB),请重新选择文件";
document.getElementById("id_button_ota_start").disabled = true;
}
else if (select_partition == "2") {
app_size = 64 * 1024;
show_info = 1;
else if (select_file_size == 0) {
document.getElementById("id_p_ota_result").innerHTML = "空文件,请重新选择文件";
document.getElementById("id_button_ota_start").disabled = true;
}
else {
app_name = "";
app_size = 0;
show_info = 0;
document.getElementById("id_p_ota_result").innerHTML = "";
document.getElementById("id_button_ota_start").disabled = false;
}
if (show_info == 1) {
if (select_file_size > app_size) {
alert("超出最大限制(" + app_size / 1024 + "KB)\nn请重新选择文件");
document.getElementById("id_button_ota_start").disabled = true;
}
else if (select_file_size == 0) {
alert('空文件\nn请重新选择文件');
document.getElementById("id_button_ota_start").disabled = true;
}
else {
document.getElementById("id_button_ota_start").disabled = false;
}
document.getElementById("id_p_select_file_name").innerHTML = "已加载文件名称:" + select_file_name;
document.getElementById("id_p_select_file_size").innerHTML = "已加载文件大小:" + get_file_size(select_file_size);
}
document.getElementById("id_p_select_file_name").innerHTML = "已加载文件名称:" + select_file_name;
document.getElementById("id_p_select_file_size").innerHTML = "已加载文件大小:" + get_file_size(select_file_size);
}
function ota_start() {
var select_partition = document.getElementById("id_select_partition").value;
var file_path = document.getElementById("id_input_file").files[0].name;
var ota_path;
if (select_partition == "1") {
ota_path = "/ota/app/esp/" + file_path;
}
else if (select_partition == "2") {
ota_path = "/ota/app/nation/" + file_path;
}
else
{
}
var ota_path = "/ota/app/" + file_path;
if (typeof (ota_path) != "undefined") {
document.getElementById("id_p_ota_start").innerHTML = "锁定页面,请务必保持WiFi在线,正在上传...";
......
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/param.h>
#include "esp_log.h"
......@@ -46,7 +41,7 @@ static void http_resp_ota_app_html(httpd_req_t *req)
extern const unsigned char ota_app_html_end[] asm("_binary_ota_app_html_end");
const size_t ota_app_html_size = (ota_app_html_end - ota_app_html_start);
ESP_LOGI(TAG, "---- 进入更新程序页面");
ESP_LOGI(TAG, "---- get into ota app page");
httpd_resp_set_type(req, "text/HTML");
httpd_resp_send(req, (const char *)ota_app_html_start, ota_app_html_size);
}
......@@ -79,7 +74,10 @@ static esp_err_t http_resp_handler(httpd_req_t *req)
static esp_err_t http_ota_app_handler(httpd_req_t *req)
{
int ret = 0;
int recv_block = 0;
int remaining = req->content_len;
int total = remaining;
double percent = 0.0;
int err_timeout_retry_cnt = 0;
ESP_LOGI(TAG, "---- expect ota data length(bytes): %d", remaining);
......@@ -130,6 +128,12 @@ static esp_err_t http_ota_app_handler(httpd_req_t *req)
else
{
remaining -= ret;
recv_block++;
if ((recv_block % 4) == 0)
{
percent = 100.0 - (double)(remaining * 100) / (double)total;
ESP_LOGI(TAG, "---- ota process: %.2f%%", percent);
}
}
}
......@@ -193,7 +197,7 @@ httpd_handle_t start_webserver(void)
// Set URI handlers
ESP_LOGI(TAG, "---- Set URI handlers");
// 注册客户端请求行为
// register client GET handle
httpd_uri_t http_resp = {
.uri = "/*",
.method = HTTP_GET,
......@@ -201,7 +205,7 @@ httpd_handle_t start_webserver(void)
.user_ctx = NULL};
httpd_register_uri_handler(server, &http_resp);
// 注册 ota_app
// register client ota app handle
httpd_uri_t http_ota_app = {
.uri = "/ota/app/*",
.method = HTTP_POST,
......@@ -212,7 +216,7 @@ httpd_handle_t start_webserver(void)
return server;
}
ESP_LOGI(TAG, "---- 服务器启动时发生错误.");
ESP_LOGI(TAG, "---- error occurred during server startup");
return NULL;
}
......@@ -226,7 +230,7 @@ void start_webserver_handler(void *arg)
httpd_handle_t *server = (httpd_handle_t *)arg;
if (*server == NULL)
{
ESP_LOGI(TAG, "---- 开启HTTP服务器");
ESP_LOGI(TAG, "---- start http server");
*server = start_webserver();
}
}
......@@ -236,7 +240,7 @@ void stop_webserver_handler(void *arg)
httpd_handle_t *server = (httpd_handle_t *)arg;
if (*server)
{
ESP_LOGI(TAG, "---- 关闭HTTP服务器");
ESP_LOGI(TAG, "---- stop http server");
if (stop_webserver(*server) == ESP_OK)
{
*server = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment