esp32c3-usb_serial/main/wifi/www/html_files.bin

580 lines
23 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<table class="fixed" border="0">
<col width="1000px" /><col width="500px" />
<tr><td>
<h2>ESP32 File Server</h2>
</td><td>
<table border="0">
<tr>
<td>
<label for="newfile">Upload a file</label>
</td>
<td colspan="2">
<input id="newfile" type="file" onchange="setpath()" style="width:100%;">
</td>
</tr>
<tr>
<td>
<label for="filepath">Set path on server</label>
</td>
<td>
<input id="filepath" type="text" style="width:100%;">
</td>
<td>
<button id="upload" type="button" onclick="upload()">Upload</button>
</td>
</tr>
</table>
</td></tr>
</table>
<script>
function setpath() {
var default_path = document.getElementById("newfile").files[0].name;
document.getElementById("filepath").value = default_path;
}
function upload() {
var filePath = document.getElementById("filepath").value;
var upload_path = "/save_file/" + filePath;
var fileInput = document.getElementById("newfile").files;
/* Max size of an individual file. Make sure this
* value is same as that set in file_server.c */
var MAX_FILE_SIZE = 2000*1024;
var MAX_FILE_SIZE_STR = "2000KB";
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 > 2000*1024) {
alert("File size must be less than 2000KB!");
} 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()
}
}
};
xhttp.open("POST", upload_path, true);
xhttp.send(file);
}
}
</script>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<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; }
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;}
.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; }
.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;}
@media screen and (max-width: 500px) {
* { 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>ESP32 Web 在 线 工 具</h2>
<form style='text-align: center;padding-top: 20px' name='input' action='/' method='POST'>
<!-- <div class="form-item">
<input id="username" type="text" name='ssid' autocomplete="off" placeholder="WiFi名称">
</div>
<div class="form-item">
<input id="password" type="password" name='password' autocomplete="off" placeholder="WiFi密码">
</div>
<div class="form-item">
<input id="retry" type="text" name='retry' autocomplete="off" placeholder="重连次数">
</div> -->
<div class="form-item">
<div id="">
<input id="Online_distribution_network" type="button" value='在线配网' onclick="location.href='/config'">
</div>
</div>
<div class="form-item">
<div id="">
<input id="Online_OTA_bin" type='button' value='在线OTA' onclick="location.href='/ota'">
</div>
</div>
<div class="form-item">
<div id="">
<input id="Online_Send_file" type='button' value='在线传输文件' onclick="location.href='/file'">
</div>
</div>
<div class="form-item">
<div id="">
<input id="send_button" type='submit' value='系统配置'>
</div>
</div>
<div class="form-item">
<div class="user_text">
<br>
<!-- <p><h3>如何获取cityCode:</h3></p> -->
<!-- <p>
<h5>
1
</h5>
</p>
<p>
<h5>
2
</h5>
</p> -->
</div>
</div>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<head>
<meta charset='UTF-8'>
<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; }
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;}
.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; }
.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;}
@media screen and (max-width: 500px) {
* { 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">
</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>
</td>
<td>
<input id="filepath" type="text" style="width:100%;">
</td>
<td>
<button id="upload" type="button" onclick="upload()">Upload</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 setpath() {
var default_path = document.getElementById("newfile").files[0].name;
document.getElementById("filepath").value = default_path;
}
function upload() {
var filePath = document.getElementById("filepath").value;
var upload_path = "/upload/" + filePath;
var fileInput = document.getElementById("newfile").files;
/* 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()
}
}
};
xhttp.open("POST", upload_path, true);
xhttp.send(file);
}
}
</script>
<table class="fixed" border="0">
<col width="1000px" /><col width="500px" />
<meta charset='UTF-8'>
<title>在线OTA更新</title>
<tr><td>
<h2>ESP32S2 OTA Bin Server</h2>
</td><td>
<table border="0">
<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>
</td>
<td>
<input id="filepath" type="text" style="width:100%;">
</td>
<td>
<button id="upload" type="button" onclick="upload()">Upload</button>
</td>
</tr>
</table>
</td></tr>
</table>
<script>
function setpath() {
var default_path = document.getElementById("newfile").files[0].name;
document.getElementById("filepath").value = default_path;
}
function upload() {
var filePath = document.getElementById("filepath").value;
var upload_path = "/upload/" + filePath;
var fileInput = document.getElementById("newfile").files;
/* 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()
}
}
};
xhttp.open("POST", upload_path, true);
xhttp.send(file);
}
}
</script>
<!DOCTYPE html>
<meta charset='UTF-8'>
<table class="fixed" border="0">
<col width="1000px" /><col width="500px" />
<h3>wifi 密码配置</h3>
<div>
<label for="name">wifi名称</label>
<input type="text" id="wifi" name="car_name" placeholder="ssid">
<br>
<label for="type">密码</label>
<input type="text" id="code" name="car_type" placeholder="password">
<br>
<button id ="send_WIFI" type="button" onclick="send_wifi()">提交</button>
</div>
</table>
<script>
function setpath() {
var default_path = document.getElementById("newfile").files[0].name;
document.getElementById("filepath").value = default_path;
}
function send_wifi() {
var input_ssid = document.getElementById("wifi").value;
var input_code = document.getElementById("code").value;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/config", true);
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
console.log(xhttp.responseText);
} else if (xhttp.status == 0) {
alert("Server closed the connection abruptly!");
location.reload()
} else {
alert(xhttp.status + " Error!\n" + xhttp.responseText);
location.reload()
}
}
};
var data = {
"wifi_name":input_ssid,
"wifi_code":input_code
}
xhttp.send(JSON.stringify(data));
}
</script>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<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; }
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;}
.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; }
.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;}
@media screen and (max-width: 500px) {
* { 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>ESP32 WIFI 配网</h2>
<form style='text-align: center;padding-top: 20px' name='input' action='/' method='POST' onsubmit="send_wifi(event)">
<div class="form-item">
<input id="username" type="text" name='ssid' autocomplete="off" placeholder="WiFi名称">
</div>
<div class="form-item">
<input id="password" type="password" name='password' autocomplete="off" placeholder="WiFi密码">
</div>
<div class="form-item">
<input id="retry" type="text" name='retry' autocomplete="off" placeholder="重连次数">
</div>
<!-- “设置” 和 “返回” 按钮并列 -->
<div class="form-item btn-group">
<input id="set_button" type="submit" value='设置' class="send_button">
<input id="back_button" type="button" value='返回' class="send_button" onclick="window.location.href='/'">
</div>
</form>
</div>
<style>
.btn-group {
display: flex;
justify-content: center; /* 水平居中 */
gap: 20px; /* 按钮之间的间距 */
}
.send_button {
display: block; /* 让 width 生效 */
width: 150px;
height: 50px;
border: 0;
border-radius: 25px;
font-size: 18px;
color: #1f6f4a;
outline: none;
cursor: pointer;
background-color: #fff;
text-align: center;
}
</style>
</body>
</html>
<script>
function send_wifi(event) {
// 通过 event.submitter 获取触发提交的按钮
let buttonId = event.submitter.id;
console.log("触发提交的按钮 ID:", buttonId);
if (buttonId === "set_button") {//只有设置按钮才能阻塞
event.preventDefault(); // 阻止表单提交
console.log("send_wifi() 函数被调用了");
// 获取 WiFi 名称和密码
let wifi_name = document.getElementById("username").value;
let wifi_password = document.getElementById("password").value;
let retry_count = document.getElementById("retry").value;
console.log("WiFi 名称:", wifi_name);
console.log("WiFi 密码:", wifi_password);
console.log("重连次数:", retry_count);
// 你可以在这里添加 AJAX 代码将数据发送到服务器
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/config", true);
xhttp.setRequestHeader("Content-Type", "application/json"); // 确保以 JSON 格式发送
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
// 解析 JSON 响应
let response = JSON.parse(xhttp.responseText);
console.log("服务器响应:", response);
if (response.status === "success") {
alert("Wi-Fi 配置成功!");
} else {
alert("Wi-Fi 配置失败!");
}
}
else if (xhttp.status == 0) {
alert("服务器连接被关闭,重新加载页面!");
location.reload()
} else {
alert(xhttp.status + " 错误!\n" + xhttp.responseText);
location.reload()
}
}
};
// 发送 JSON 数据
var data = {
"wifi_name": wifi_name,
"wifi_code": wifi_password,
"retry_count": retry_count
};
xhttp.send(JSON.stringify(data));
}
}
// function setpath() {
// var default_path = document.getElementById("newfile").files[0].name;
// document.getElementById("filepath").value = default_path;
// }
</script>