Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
QJ_500-7c
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
QJ_500-7c
Commits
82ea894f
Commit
82ea894f
authored
Nov 01, 2024
by
李延凯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 修改升级页面格式, 删除不必要代码
parent
10c9f727
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
76 deletions
+30
-76
ota_app.html
qianjiang/source/http_user/html/ota_app.html
+15
-65
http_service.c
qianjiang/source/http_user/http_service.c
+15
-11
No files found.
qianjiang/source/http_user/html/ota_app.html
View file @
82ea894f
...
...
@@ -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>
<!-- 页面重置超链接 -->
<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)
\n
n请重新选择文件"
);
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在线,正在上传..."
;
...
...
qianjiang/source/http_user/http_service.c
View file @
82ea894f
#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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment