Compare commits
No commits in common. "98dfc91e52ac2a9fe83e153c8bdaf4a9be481eae" and "3cebcde66ca407542b7063c944a5217b814a2ade" have entirely different histories.
98dfc91e52
...
3cebcde66c
18
main/main.c
18
main/main.c
@ -73,9 +73,9 @@ static void echo_task(void *arg)
|
||||
// Write data back to the USB SERIAL JTAG
|
||||
if (len) {
|
||||
// usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
||||
// uart_write_bytes(EX_UART_NUM, (const char *) data, len);
|
||||
uart_write_bytes(EX_UART_NUM, (const char *) data, len);
|
||||
data[len] = '\0';
|
||||
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||
// ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -224,27 +224,15 @@ void app_main(void)
|
||||
//Install UART driver, and get the queue.
|
||||
// uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
|
||||
// uart_param_config(EX_UART_NUM, &uart_config);
|
||||
xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||
// xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||
//Create a task to handler UART event from ISR
|
||||
// xTaskCreate(uart_event_task, "uart_event_task", 2048*10, NULL, 12, NULL);
|
||||
|
||||
home_html.html_data = load_html2Ram(home_html);
|
||||
wifi_config_html.html_data = load_html2Ram(wifi_config_html);
|
||||
upload_ota_html.html_data = load_html2Ram(upload_ota_html);
|
||||
// favicon_ico.html_data = load_html2Ram(favicon_ico);
|
||||
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||
// ESP_LOGI(TAG,"def_name:%s",Sys_wifi_config.def_AP_Name);
|
||||
ESP_LOGI(TAG,"sizeof--Sys_wifi_config:%d",sizeof(wifi_Save_info_t));
|
||||
Read_ESPFlash(0x40,0,&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
||||
ESP_LOGI(TAG,"wifi_ssid:%s",Sys_wifi_config.wifi_ssid);
|
||||
ESP_LOGI(TAG,"wifi_password:%s",Sys_wifi_config.wifi_password);
|
||||
if(Sys_wifi_config.wifi_mode != 0x55)
|
||||
{
|
||||
wifi_init_softap();
|
||||
}else{
|
||||
wifi_init_station();
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||
start_web_server();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "wifi_task.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_vfs.h"
|
||||
#include "bsp_flash.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
static const char *TAG = "wifi_html";
|
||||
|
||||
@ -18,29 +18,16 @@ wifi_html_t home_html = {
|
||||
|
||||
wifi_html_t wifi_config_html = {
|
||||
.html_name = "wifi_config.html",
|
||||
.html_addr = 0x4115,
|
||||
.html_addr = 0x44b9,
|
||||
.html_size = 6671,
|
||||
};
|
||||
|
||||
wifi_html_t upload_ota_html = {
|
||||
.html_name = "upload_script.html",
|
||||
.html_addr = 0x1b75,
|
||||
.html_size = 4951,
|
||||
};
|
||||
|
||||
wifi_html_t favicon_ico = {
|
||||
.html_name = "favicon.ico",
|
||||
.html_addr = 0,
|
||||
.html_size = 106008,
|
||||
};
|
||||
|
||||
static esp_err_t ota_get_handler(httpd_req_t *req)
|
||||
{
|
||||
/* Add file upload form and script which on execution sends a POST request to /upload */
|
||||
httpd_resp_set_type(req,HTTPD_TYPE_TEXT);
|
||||
httpd_resp_send(req, (const char *)upload_ota_html.html_data, upload_ota_html.html_size);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t index_get_handler(httpd_req_t *req)
|
||||
{
|
||||
@ -121,14 +108,27 @@ static esp_err_t wifi_config_handler(httpd_req_t *req)
|
||||
printf("%c",wifi_password[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
// esp_err_t e = httpd_query_key_value(buf,"wifi_name",wifi_name,sizeof(wifi_name));
|
||||
// if(e == ESP_OK) {
|
||||
// printf("ssid = %s\r\n",wifi_name);
|
||||
// }
|
||||
// else {
|
||||
// printf("error = %d\r\n",e);
|
||||
// }
|
||||
|
||||
sprintf(Sys_wifi_config.wifi_ssid,"%s",wifi_name);
|
||||
sprintf(Sys_wifi_config.wifi_password,"%s",wifi_password);
|
||||
Sys_wifi_config.wifi_mode = 0x55;
|
||||
// e = httpd_query_key_value(buf,"wifi_code",wifi_password,sizeof(wifi_password));
|
||||
// if(e == ESP_OK) {
|
||||
// printf("pswd = %s\r\n",wifi_password);
|
||||
// }
|
||||
// else {
|
||||
// printf("error = %d\r\n",e);
|
||||
// }
|
||||
// sprintf(esp_wifi_info.ssid,"%s",wifi_name);
|
||||
// sprintf(esp_wifi_info.password,"%s",wifi_password);
|
||||
// esp_wifi_info.reboot = false;
|
||||
// wifi_config_data.SubType = 0x40;
|
||||
// wifi_config_data.addr = 0;
|
||||
Write_ESPFlash(0x40,0,(uint8_t *)&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
||||
// Write_ESPFlash(wifi_config_data.SubType,wifi_config_data.addr,(uint8_t *)&wifi_config_data,sizeof(struct save_flash_t) + sizeof(wifi_info_t));
|
||||
|
||||
/* Log data received */
|
||||
ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
|
||||
@ -284,16 +284,6 @@ esp_err_t start_web_server(void)
|
||||
};
|
||||
httpd_register_uri_handler(server, &home_page);
|
||||
|
||||
httpd_uri_t ota_page = {
|
||||
.uri = "/ota", //192.168.1.4
|
||||
.method = HTTP_GET,
|
||||
.handler = ota_get_handler,
|
||||
/* Let's pass response string in user
|
||||
* context to demonstrate it's usage */
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
httpd_register_uri_handler(server, &ota_page);
|
||||
|
||||
httpd_uri_t echo = {
|
||||
.uri = "/config",
|
||||
.method = HTTP_POST,
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include "wifi_task.h"
|
||||
#include "bsp_flash.h"
|
||||
|
||||
|
||||
static const char *TAG = "wifi_sta";
|
||||
|
||||
#define EXAMPLE_ESP_WIFI_SSID "A-301-55"
|
||||
#define EXAMPLE_ESP_WIFI_PASS "whyt2019"
|
||||
#define EXAMPLE_ESP_WIFI_SSID "Yu886"
|
||||
#define EXAMPLE_ESP_WIFI_PASS "2023yu2023"
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
|
||||
|
||||
|
||||
@ -83,10 +83,6 @@ void wifi_init_station(void)
|
||||
.sae_h2e_identifier = "",
|
||||
},
|
||||
};
|
||||
memset(&wifi_config.sta.ssid[0],0x00,sizeof(wifi_config.sta.ssid));
|
||||
memset(&wifi_config.sta.password[0],0x00,sizeof(wifi_config.sta.password));
|
||||
memcpy(&wifi_config.sta.ssid[0],Sys_wifi_config.wifi_ssid,strlen(Sys_wifi_config.wifi_ssid));
|
||||
memcpy(&wifi_config.sta.password[0],Sys_wifi_config.wifi_password,strlen(Sys_wifi_config.wifi_password));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
@ -112,11 +108,6 @@ void wifi_init_station(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
|
||||
Sys_wifi_config.wifi_mode = 0x00;
|
||||
Write_ESPFlash(0x40,0,(uint8_t *)&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
||||
vTaskDelay(100/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -8,11 +8,6 @@ static const char *TAG = "wifi_task";
|
||||
#define KEEPALIVE_COUNT 3
|
||||
|
||||
|
||||
|
||||
wifi_Save_info_t Sys_wifi_config = {
|
||||
// .def_AP_Name = "ESP32_Online_Link",
|
||||
};
|
||||
|
||||
static void do_retransmit(const int sock)
|
||||
{
|
||||
int len;
|
||||
|
||||
@ -35,21 +35,9 @@ typedef struct wifi_html_
|
||||
uint8_t* html_data;
|
||||
}wifi_html_t;
|
||||
|
||||
typedef struct wifi_Save_info_
|
||||
{
|
||||
char wifi_ssid[24];
|
||||
char wifi_password[24];
|
||||
uint8_t retry_count;
|
||||
uint8_t wifi_mode;
|
||||
}wifi_Save_info_t;
|
||||
|
||||
|
||||
extern wifi_Save_info_t Sys_wifi_config;
|
||||
|
||||
extern wifi_html_t home_html;
|
||||
extern wifi_html_t wifi_config_html;
|
||||
extern wifi_html_t favicon_ico;
|
||||
extern wifi_html_t upload_ota_html;
|
||||
|
||||
void wifi_init_station(void);
|
||||
void wifi_init_softap(void);
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
},
|
||||
{
|
||||
"url": "/upload_script.html",
|
||||
"size": 4951,
|
||||
"size": 5883,
|
||||
"name": "upload_script.html",
|
||||
"address": "0x1b75"
|
||||
},
|
||||
@ -21,18 +21,18 @@
|
||||
"url": "/upload_script_copy.html",
|
||||
"size": 3046,
|
||||
"name": "upload_script_copy.html",
|
||||
"address": "0x2ecc"
|
||||
"address": "0x3270"
|
||||
},
|
||||
{
|
||||
"url": "/wifi.html",
|
||||
"size": 1635,
|
||||
"name": "wifi.html",
|
||||
"address": "0x3ab2"
|
||||
"address": "0x3e56"
|
||||
},
|
||||
{
|
||||
"url": "/wifi_config.html",
|
||||
"size": 6671,
|
||||
"name": "wifi_config.html",
|
||||
"address": "0x4115"
|
||||
"address": "0x44b9"
|
||||
}
|
||||
]
|
||||
@ -180,163 +180,127 @@ function upload() {
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
||||
<title>在线配置</title>
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body { height: 100%; background-color: #1F6F4A; display: flex; align-items: center; justify-content: center; }
|
||||
* { margin: 0; padding: 0; }
|
||||
html { height: 100%; }
|
||||
h2 {text-align: center;color: #fff;line-height: 2.2;}
|
||||
body { height: 100%; background-color: #1F6F4A; 50% 50% no-repeat; background-size: cover;}
|
||||
.dowebok { position: absolute; left: 50%; top: 30%; width: 380px; height: 500px; margin: -200px 0 0 -200px; border: 3px solid #fff; border-radius: 10px; overflow: hidden;}
|
||||
|
||||
h2, label { text-align: center; color: #fff; line-height: 2.2; }
|
||||
.form-item { position: relative; width: 360px; margin: 0 auto; padding-bottom: 20px;}
|
||||
.form-item input { width: 288px; height: 48px; padding-left: 10px; border: 1px solid #fff; border-radius: 25px; font-size: 18px; color: #fff; background-color: transparent; outline: none;}
|
||||
.send_button { width: 360px; height: 50px; border: 0; border-radius: 25px; font-size: 18px; color: #1f6f4a; outline: none; cursor: pointer; background-color: #fff; }
|
||||
|
||||
.dowebok {
|
||||
width: 380px;
|
||||
height: 500px;
|
||||
border: 3px solid #fff;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.tip { display: none; position: absolute; left: 20px; top: 52px; font-size: 14px; color: #f50; }
|
||||
.reg-bar { width: 360px; margin: 20px auto 0; font-size: 14px; overflow: hidden;}
|
||||
.reg-bar a { color: #fff; text-decoration: none; }
|
||||
.reg-bar a:hover { text-decoration: underline; }
|
||||
.reg-bar .reg { float: left; }
|
||||
.reg-bar .forget { float: right; }
|
||||
.dowebok ::-webkit-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok ::-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-ms-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
|
||||
.form-item {
|
||||
width: 100%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 自定义文件上传区域 */
|
||||
.custom-file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 5px;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
.custom-file span {
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
flex-grow: 1;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.custom-file label {
|
||||
background-color: #fff;
|
||||
color: #1F6F4A;
|
||||
padding: 6px 12px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.custom-file input {
|
||||
display: none; /* 隐藏原始文件选择框 */
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 5px;
|
||||
padding-left: 10px;
|
||||
color: #fff;
|
||||
background-color: transparent;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background-color: #fff;
|
||||
color: #1F6F4A;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media screen and (max-width: 500px) {
|
||||
.dowebok { width: 90%; height: auto; padding: 10px; }
|
||||
* { box-sizing: border-box; }
|
||||
.dowebok { position: static; width: auto; height: auto; margin: 0 30px; border: 0; border-radius: 0; }
|
||||
.logo { margin: 50px auto; }
|
||||
.form-item { width: auto; }
|
||||
.form-item input, .form-item button, .reg-bar { width: 100%; }
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dowebok">
|
||||
<h2>ESP32S2 OTA Bin Server</h2>
|
||||
<!-- <table border="0">
|
||||
|
||||
<!-- 自定义文件选择框 -->
|
||||
<div class="form-item">
|
||||
<div class="custom-file">
|
||||
<span id="file-name">未选择文件</span>
|
||||
<label for="newfile">选择文件</label>
|
||||
<input id="newfile" type="file" accept=".bin" onchange="updateFileName()">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
</table> -->
|
||||
<tr>
|
||||
<td>
|
||||
<label for="newfile">Upload a file</label>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<input id="newfile" type="file" accept=".bin" onchange="setpath()" style="width:100%;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="filepath">Set path on server </label>
|
||||
<input id="filepath" type="text" readonly>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<input id="filepath" type="text" style="width:100%;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
<br><br>
|
||||
<button onclick="window.location.href='/'">返回</button>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- <form style='text-align: center;padding-top: 20px' action='/ota' method='POST'>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</form> -->
|
||||
<form style='text-align: center;padding-top: 20px' name='input' action='/config' method='POST'>
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="return_page" type='button' value='返回' onclick="location.href='/'">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
function updateFileName() {
|
||||
var fileInput = document.getElementById("newfile");
|
||||
var fileNameSpan = document.getElementById("file-name");
|
||||
var filePathInput = document.getElementById("filepath");
|
||||
|
||||
if (fileInput.files.length > 0) {
|
||||
var file = fileInput.files[0];
|
||||
var fileSize = formatFileSize(file.size);
|
||||
fileNameSpan.textContent = file.name;
|
||||
filePathInput.value = `${file.name} (${fileSize})`;
|
||||
} else {
|
||||
fileNameSpan.textContent = "未选择文件";
|
||||
filePathInput.value = "";
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
}
|
||||
|
||||
// 文件大小格式化
|
||||
function formatFileSize(size) {
|
||||
if (size < 1024) return size + " B";
|
||||
else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + " KB";
|
||||
else return (size / (1024 * 1024)).toFixed(2) + " MB";
|
||||
}
|
||||
|
||||
function upload() {
|
||||
var fileInput = document.getElementById("newfile");
|
||||
var filePath = document.getElementById("filepath").value;
|
||||
var upload_path = "/upload/" + filePath;
|
||||
var fileInput = document.getElementById("newfile").files;
|
||||
|
||||
if (fileInput.files.length === 0) {
|
||||
alert("请先选择一个文件!");
|
||||
return;
|
||||
/* Max size of an individual file. Make sure this
|
||||
* value is same as that set in file_server.c */
|
||||
var MAX_FILE_SIZE = 20*1024*1024;
|
||||
var MAX_FILE_SIZE_STR = "20MB";
|
||||
|
||||
if (fileInput.length == 0) {
|
||||
alert("No file selected!");
|
||||
} else if (filePath.length == 0) {
|
||||
alert("File path on server is not set!");
|
||||
} else if (filePath.indexOf(' ') >= 0) {
|
||||
alert("File path on server cannot have spaces!");
|
||||
} else if (filePath[filePath.length-1] == '/') {
|
||||
alert("File name not specified after path!");
|
||||
} else if (fileInput[0].size > MAX_FILE_SIZE) {
|
||||
alert("File size must be less than " + MAX_FILE_SIZE_STR);
|
||||
} else {
|
||||
document.getElementById("newfile").disabled = true;
|
||||
document.getElementById("filepath").disabled = true;
|
||||
document.getElementById("upload").disabled = true;
|
||||
|
||||
var file = fileInput[0];
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
document.open();
|
||||
document.write(xhttp.responseText);
|
||||
document.close();
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("file", fileInput.files[0]);
|
||||
formData.append("path", filePath);
|
||||
|
||||
fetch("/upload", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
}).then(response => response.text())
|
||||
.then(data => alert("上传成功:" + data))
|
||||
.catch(error => alert("上传失败:" + error));
|
||||
};
|
||||
xhttp.open("POST", upload_path, true);
|
||||
xhttp.send(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<table class="fixed" border="0">
|
||||
|
||||
@ -4,162 +4,126 @@
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
||||
<title>在线配置</title>
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body { height: 100%; background-color: #1F6F4A; display: flex; align-items: center; justify-content: center; }
|
||||
* { margin: 0; padding: 0; }
|
||||
html { height: 100%; }
|
||||
h2 {text-align: center;color: #fff;line-height: 2.2;}
|
||||
body { height: 100%; background-color: #1F6F4A; 50% 50% no-repeat; background-size: cover;}
|
||||
.dowebok { position: absolute; left: 50%; top: 30%; width: 380px; height: 500px; margin: -200px 0 0 -200px; border: 3px solid #fff; border-radius: 10px; overflow: hidden;}
|
||||
|
||||
h2, label { text-align: center; color: #fff; line-height: 2.2; }
|
||||
.form-item { position: relative; width: 360px; margin: 0 auto; padding-bottom: 20px;}
|
||||
.form-item input { width: 288px; height: 48px; padding-left: 10px; border: 1px solid #fff; border-radius: 25px; font-size: 18px; color: #fff; background-color: transparent; outline: none;}
|
||||
.send_button { width: 360px; height: 50px; border: 0; border-radius: 25px; font-size: 18px; color: #1f6f4a; outline: none; cursor: pointer; background-color: #fff; }
|
||||
|
||||
.dowebok {
|
||||
width: 380px;
|
||||
height: 500px;
|
||||
border: 3px solid #fff;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.tip { display: none; position: absolute; left: 20px; top: 52px; font-size: 14px; color: #f50; }
|
||||
.reg-bar { width: 360px; margin: 20px auto 0; font-size: 14px; overflow: hidden;}
|
||||
.reg-bar a { color: #fff; text-decoration: none; }
|
||||
.reg-bar a:hover { text-decoration: underline; }
|
||||
.reg-bar .reg { float: left; }
|
||||
.reg-bar .forget { float: right; }
|
||||
.dowebok ::-webkit-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok ::-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-ms-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
|
||||
.form-item {
|
||||
width: 100%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* 自定义文件上传区域 */
|
||||
.custom-file {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 5px;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
.custom-file span {
|
||||
color: white;
|
||||
font-size: 16px;
|
||||
flex-grow: 1;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.custom-file label {
|
||||
background-color: #fff;
|
||||
color: #1F6F4A;
|
||||
padding: 6px 12px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.custom-file input {
|
||||
display: none; /* 隐藏原始文件选择框 */
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 5px;
|
||||
padding-left: 10px;
|
||||
color: #fff;
|
||||
background-color: transparent;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background-color: #fff;
|
||||
color: #1F6F4A;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media screen and (max-width: 500px) {
|
||||
.dowebok { width: 90%; height: auto; padding: 10px; }
|
||||
* { box-sizing: border-box; }
|
||||
.dowebok { position: static; width: auto; height: auto; margin: 0 30px; border: 0; border-radius: 0; }
|
||||
.logo { margin: 50px auto; }
|
||||
.form-item { width: auto; }
|
||||
.form-item input, .form-item button, .reg-bar { width: 100%; }
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dowebok">
|
||||
<h2>ESP32S2 OTA Bin Server</h2>
|
||||
<!-- <table border="0">
|
||||
|
||||
<!-- 自定义文件选择框 -->
|
||||
<div class="form-item">
|
||||
<div class="custom-file">
|
||||
<span id="file-name">未选择文件</span>
|
||||
<label for="newfile">选择文件</label>
|
||||
<input id="newfile" type="file" accept=".bin" onchange="updateFileName()">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
</table> -->
|
||||
<tr>
|
||||
<td>
|
||||
<label for="newfile">Upload a file</label>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<input id="newfile" type="file" accept=".bin" onchange="setpath()" style="width:100%;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="filepath">Set path on server </label>
|
||||
<input id="filepath" type="text" readonly>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<input id="filepath" type="text" style="width:100%;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
<br><br>
|
||||
<button onclick="window.location.href='/'">返回</button>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- <form style='text-align: center;padding-top: 20px' action='/ota' method='POST'>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</form> -->
|
||||
<form style='text-align: center;padding-top: 20px' name='input' action='/config' method='POST'>
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="return_page" type='button' value='返回' onclick="location.href='/'">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
function updateFileName() {
|
||||
var fileInput = document.getElementById("newfile");
|
||||
var fileNameSpan = document.getElementById("file-name");
|
||||
var filePathInput = document.getElementById("filepath");
|
||||
|
||||
if (fileInput.files.length > 0) {
|
||||
var file = fileInput.files[0];
|
||||
var fileSize = formatFileSize(file.size);
|
||||
fileNameSpan.textContent = file.name;
|
||||
filePathInput.value = `${file.name} (${fileSize})`;
|
||||
} else {
|
||||
fileNameSpan.textContent = "未选择文件";
|
||||
filePathInput.value = "";
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
}
|
||||
|
||||
// 文件大小格式化
|
||||
function formatFileSize(size) {
|
||||
if (size < 1024) return size + " B";
|
||||
else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + " KB";
|
||||
else return (size / (1024 * 1024)).toFixed(2) + " MB";
|
||||
}
|
||||
|
||||
function upload() {
|
||||
var fileInput = document.getElementById("newfile");
|
||||
var filePath = document.getElementById("filepath").value;
|
||||
var upload_path = "/upload/" + filePath;
|
||||
var fileInput = document.getElementById("newfile").files;
|
||||
|
||||
if (fileInput.files.length === 0) {
|
||||
alert("请先选择一个文件!");
|
||||
return;
|
||||
/* Max size of an individual file. Make sure this
|
||||
* value is same as that set in file_server.c */
|
||||
var MAX_FILE_SIZE = 20*1024*1024;
|
||||
var MAX_FILE_SIZE_STR = "20MB";
|
||||
|
||||
if (fileInput.length == 0) {
|
||||
alert("No file selected!");
|
||||
} else if (filePath.length == 0) {
|
||||
alert("File path on server is not set!");
|
||||
} else if (filePath.indexOf(' ') >= 0) {
|
||||
alert("File path on server cannot have spaces!");
|
||||
} else if (filePath[filePath.length-1] == '/') {
|
||||
alert("File name not specified after path!");
|
||||
} else if (fileInput[0].size > MAX_FILE_SIZE) {
|
||||
alert("File size must be less than " + MAX_FILE_SIZE_STR);
|
||||
} else {
|
||||
document.getElementById("newfile").disabled = true;
|
||||
document.getElementById("filepath").disabled = true;
|
||||
document.getElementById("upload").disabled = true;
|
||||
|
||||
var file = fileInput[0];
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
document.open();
|
||||
document.write(xhttp.responseText);
|
||||
document.close();
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("file", fileInput.files[0]);
|
||||
formData.append("path", filePath);
|
||||
|
||||
fetch("/upload", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
}
|
||||
}).then(response => response.text())
|
||||
.then(data => alert("上传成功:" + data))
|
||||
.catch(error => alert("上传失败:" + error));
|
||||
};
|
||||
xhttp.open("POST", upload_path, true);
|
||||
xhttp.send(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user