new OTA page

This commit is contained in:
Siwat Sirichai 2023-11-07 16:03:46 +07:00
parent 897d8694e1
commit 1128de9297
16 changed files with 357 additions and 218 deletions

View File

@ -245,12 +245,19 @@ void ota_begin()
otaserver.on("/", HTTP_GET, []()
{
otaserver.sendHeader("Connection", "close");
String otabuffer = ota_part1+HOSTNAME+ota_part2+IP.toString()+ota_part3+ETH.macAddress()+ota_part4+ESPMEGA_REV+ota_part5+MQTT_SERVER.toString()+ota_part6+String(MQTT_BASE_TOPIC)+ota_part7;
String otabuffer = ota_part1;
otabuffer+=ota_part2_1+"Hostname"+ota_part2_2+String(HOSTNAME)+ota_part2_3;
otabuffer+=ota_part2_1+"IP Address"+ota_part2_2+IP.toString()+ota_part2_3;
otabuffer+=ota_part2_1+"MAC Address"+ota_part2_2+ETH.macAddress()+ota_part2_3;
otabuffer+=ota_part2_1+"Device"+ota_part2_2+ESPMEGA_REV+ota_part2_3;
otabuffer+=ota_part2_1+"BMS Server"+ota_part2_2+MQTT_SERVER.toString()+ota_part2_3;
otabuffer+=ota_part2_1+"BMS Endpoint"+ota_part2_2+String(MQTT_BASE_TOPIC)+ota_part2_3;
otabuffer+=ota_part2_1+"Centrally Managed"+ota_part2_2;
if(standalone)
otabuffer+=String("No");
else
otabuffer+=String("Yes");
otabuffer+=ota_part8;
otabuffer+=ota_part2_3+ota_part3;
otaserver.send(200, "text/html", otabuffer); });
otaserver.on(
"/update", HTTP_POST, []()

View File

@ -3,24 +3,15 @@
const String ota_part1 = {
#include "ota_html/ota-part1.html"
};
const String ota_part2 = {
#include "ota_html/ota-part2.html"
const String ota_part2_1 = {
#include "ota_html/ota-part2-1_itr.html"
};
const String ota_part2_2 = {
#include "ota_html/ota-part2-2_itr.html"
};
const String ota_part2_3 = {
#include "ota_html/ota-part2-3_itr.html"
};
const String ota_part3 = {
#include "ota_html/ota-part3.html"
};
const String ota_part4 = {
#include "ota_html/ota-part4.html"
};
const String ota_part5 = {
#include "ota_html/ota-part5.html"
};
const String ota_part6 = {
#include "ota_html/ota-part6.html"
};
const String ota_part7 = {
#include "ota_html/ota-part7.html"
};
const String ota_part8 = {
#include "ota_html/ota-part8.html"
};

View File

@ -1,10 +1,7 @@
#pragma once
#include <ESPMegaPRO.h>
extern const String ota_part1;
extern const String ota_part2;
extern const String ota_part2_1;
extern const String ota_part2_2;
extern const String ota_part2_3;
extern const String ota_part3;
extern const String ota_part4;
extern const String ota_part5;
extern const String ota_part6;
extern const String ota_part7;
extern const String ota_part8;

View File

@ -0,0 +1,188 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form enctype="multipart/form-data" id="config_form" onsubmit="send_config()" action="/save_config">
<h1>ESPMega PRO</h1>
<h3>Device Configurations</h3>
<p class="config_title">IP Address</p>
<input type="text" id="dev_ip" name="dev_ip" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Network Mask</p>
<input type="text" id="netmask" name="netmask" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Gateway</p>
<input type="text" id="gateway" name="gateway" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">DNS Server</p>
<input type="text" id="dns" name="dns" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Hostname</p>
<input type="text" id="hostname" name="hostname" class="conf_txt" value="ESPMegaPRO"><br>
<p class="config_title">BMS Server - IP Address</p>
<input type="text" id="bms_ip" name="bms_ip" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">BMS Server - Port</p>
<input type="text" id="bms_port" name="bms_port" class="conf_txt" value="1883"><br>
<label class="container">Authentication
<input type="checkbox" name="bms_useauth" id="bms_useauth" checked="checked" value="yes">
<span class="checkmark"></span>
</label>
<p class="config_title">BMS Server - Username</p>
<input type="text" id="bms_username" name="bms_username" class="conf_txt" value="user"><br>
<p class="config_title">BMS Server - Password</p>
<input type="password" id="bms_password" name="bms_password" class="conf_txt" value="password"><br>
<p class="config_title">BMS Server - Endpoint</p>
<input type="text" id="bms_endpoint" name="bms_endpoint" class="conf_txt" value="/espmegapro"><br>
<input type="submit" class="btn" value="Save">
<b>SIWAT SYSTEM 2023</b>
</form>
<style>
p.config_title {
font-size: 12;
font-weight: bold;
text-align: left;
align-self: left;
margin-bottom: 0;
margin-top: 0;
}
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
}
.conf_txt {
background-color: #e2e2e2;
}
.checkbox {
size: 4;
display: inline-block;
}
.container {
display: block;
position: relative;
padding-left: 0px;
margin-bottom: 12px;
cursor: pointer;
font-size: 20px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
.container:hover input ~ .checkmark {
background-color: #ccc;
}
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.container input:checked ~ .checkmark:after {
display: block;
}
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>

View File

@ -29,32 +29,6 @@
<input type="submit" class="btn" value="Save">
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function send_config() {
var form = $("#config_form")[0];
var data = new FormData(form);
var dev_ip = data.get("dev_ip")
var netmask = data.get("netmask")
var gateway = data.get("gateway")
var dns = data.get("dns")
var bms_ip = data.get("bms_ip")
var bms_port = data.get("bms_port")
var bms_useauth = data.get("bms_useauth")
var bms_username = data.get("bms_username")
var bms_password = data.get("bms_password")
var bms_endpoint = data.get("bms_endpoint")
}
// $("form").submit(function (e) {
// e.preventDefault();
// var form = $("#config_form")[0];
// var data = new FormData(form);
// console.log(data)
// $.ajax({
// //Insert Configuration Upload Code
// });
// });
</script>
<style>
p.config_title {
font-size: 12;
@ -165,7 +139,6 @@
user-select: none;
}
/* Hide the browser's default checkbox */
.container input {
position: absolute;
opacity: 0;
@ -174,7 +147,6 @@
width: 0;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
@ -184,29 +156,24 @@
background-color: #eee;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container .checkmark:after {
left: 9px;
top: 5px;

View File

@ -1,8 +1,4 @@
R"=====(<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
<h1>ESPMega PRO</h1>
<h3>Software Management</h3>
<p style="text-align: left">
Hostname
<span style="float: right">)====="
<h3>Device Information</h3>)====="

View File

@ -0,0 +1 @@
R"=====(<p style="text-align: left">)====="

View File

@ -0,0 +1 @@
R"=====(<span style="float: right">)====="

View File

@ -0,0 +1,2 @@
R"=====(</span>
</p>)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
IP Address
<span style="float: right">)====="

View File

@ -1,5 +1,144 @@
R"=====(</span>
</p>
<p style="text-align: left">
MAC Address
<span style="float: right">)====="
R"=====(<button type="button" class="conf" onclick="window.location.href='config.html'">Settings</button><br /><br />
<hr>
<h3>Upload Software Package</h3>
<input type="file" name="update" id="file" onchange="sub(this)" style="display: none" />
<label id="file-input" for="file">Choose file...</label>
<input type="submit" class="btn" value="Program" /><br /><br />
<div id="prg"></div>
<br />
<div id="prgbar">
<div id="bar"></div>
</div>
<br />
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function sub(obj) {
var fileName = obj.value.split("\\");
document.getElementById("file-input").innerHTML =
" " + fileName[fileName.length - 1];
}
$("form").submit(function (e) {
e.preventDefault();
var form = $("#upload_form")[0];
var data = new FormData(form);
$.ajax({
url: "/update",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(
"progress",
function (evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
if (Math.round(per * 100) < 100) {
$("#prg").html("Updating . . . (" + Math.round(per * 100) + "%)");
}
else {
$("#prg").html("Update Completed, Rebooting . . .");
}
$("#bar").css("width", Math.round(per * 100) + "%");
}
},
false
);
return xhr;
},
success: function (d, s) {
console.log("success!");
},
error: function (a, b, c) { },
});
});
</script>
<style>
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
border: 0;
}
</style>)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
Device
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
API Server
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
API Endpoint
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
Centrally Managed
<span style="float: right">)====="

View File

@ -1,125 +0,0 @@
R"=====(</span>
</p>
<input
type="file"
name="update"
id="file"
onchange="sub(this)"
style="display: none"
/>
<label id="file-input" for="file">Choose file...</label>
<input type="submit" class="btn" value="Program" /><br /><br />
<div id="prg"></div>
<br />
<div id="prgbar">
<div id="bar"></div>
</div>
<br />
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function sub(obj) {
var fileName = obj.value.split("\\");
document.getElementById("file-input").innerHTML =
" " + fileName[fileName.length - 1];
}
$("form").submit(function (e) {
e.preventDefault();
var form = $("#upload_form")[0];
var data = new FormData(form);
$.ajax({
url: "/update",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(
"progress",
function (evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
if(Math.round(per*100)<100) {
$("#prg").html("Updating . . . (" + Math.round(per * 100) + "%)");
}
else {
$("#prg").html("Update Completed, Rebooting . . .");
}
$("#bar").css("width", Math.round(per * 100) + "%");
}
},
false
);
return xhr;
},
success: function (d, s) {
console.log("success!");
},
error: function (a, b, c) {},
});
});
</script>
<style>
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255,255,255,0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
</style>)====="