initial
This commit is contained in:
84
main/index.hpp
Normal file
84
main/index.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
#ifndef INDEX_HPP
|
||||
#define INDEX_HPP
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
const char index_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html>
|
||||
<head>
|
||||
<title>ESP Web Server</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="data:,">
|
||||
<style>
|
||||
html {font-family: Arial; display: inline-block; text-align: center;}
|
||||
h2 {font-size: 3.0rem;}
|
||||
p {font-size: 3.0rem;}
|
||||
body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}
|
||||
.switch {position: relative; display: inline-block; width: 120px; height: 68px}
|
||||
.switch input {display: none}
|
||||
.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 6px}
|
||||
.slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 3px}
|
||||
input:checked+.slider {background-color: #b30000}
|
||||
input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}
|
||||
.input-group {margin: 20px 0;}
|
||||
label {font-size: 1.2rem;}
|
||||
input[type='text'] {font-size: 1.2rem; padding: 5px;}
|
||||
button {font-size: 1.2rem; padding: 10px 20px; margin: 10px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Beacon Config</h2>
|
||||
<div id="config">
|
||||
<h3>Device Config</h3>
|
||||
<div class="input-group">
|
||||
<label for="mac_address">MAC Address (hex, colon separated):</label>
|
||||
<input type="text" id="mac_address" value="" placeholder="34:85:18:A9:3D:FC">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="beacon_id">Beacon ID (hex):</label>
|
||||
<input type="text" id="beacon_id" value="" placeholder="AABBCCDD">
|
||||
</div>
|
||||
<button onclick="saveConfig()">Save Config</button>
|
||||
<button onclick="restartSystem()">Restart System</button>
|
||||
<p id="status"></p>
|
||||
</div>
|
||||
<script>
|
||||
function toHex(num, len=2) {
|
||||
return num.toString(16).toUpperCase().padStart(len, '0');
|
||||
}
|
||||
function fetchConfig() {
|
||||
fetch('/config').then(r => r.json()).then(cfg => {
|
||||
document.getElementById('mac_address').value = cfg.mac_address.map(x => toHex(x)).join(':');
|
||||
document.getElementById('beacon_id').value = toHex(cfg.beacon_id, 8);
|
||||
});
|
||||
}
|
||||
function saveConfig() {
|
||||
const mac = document.getElementById('mac_address').value;
|
||||
const beacon = document.getElementById('beacon_id').value;
|
||||
// Convert MAC from hex string to decimal array for backend
|
||||
const macArr = mac.split(':').map(x => parseInt(x, 16));
|
||||
const macDec = macArr.join(',');
|
||||
const beaconDec = parseInt(beacon, 16);
|
||||
const params = new URLSearchParams();
|
||||
params.append('mac_address', macDec);
|
||||
params.append('beacon_id', beaconDec);
|
||||
fetch('/config', {
|
||||
method: 'POST',
|
||||
body: params
|
||||
}).then(r => r.text()).then(txt => {
|
||||
document.getElementById('status').innerText = txt;
|
||||
fetchConfig();
|
||||
});
|
||||
}
|
||||
function restartSystem() {
|
||||
fetch('/restart', {method: 'POST'}).then(r => r.text()).then(txt => {
|
||||
document.getElementById('status').innerText = txt;
|
||||
});
|
||||
}
|
||||
window.onload = fetchConfig;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user