675 lines
23 KiB
C++
675 lines
23 KiB
C++
#ifndef SETTINGS_H
|
||
#define SETTINGS_H
|
||
|
||
const char settings_html PROGMEM = R"rawliteral(
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||
<title>Settings - Byun CAN Logger v2.5</title>
|
||
<style>
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
body {
|
||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||
min-height: 100vh;
|
||
padding: 10px;
|
||
}
|
||
.container {
|
||
max-width: 900px;
|
||
margin: 0 auto;
|
||
background: white;
|
||
border-radius: 15px;
|
||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||
overflow: hidden;
|
||
}
|
||
.header {
|
||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||
color: white;
|
||
padding: 20px;
|
||
text-align: center;
|
||
}
|
||
.header h1 { font-size: 1.8em; margin-bottom: 5px; }
|
||
.header p { opacity: 0.9; font-size: 0.9em; }
|
||
.nav {
|
||
background: #2c3e50;
|
||
padding: 10px;
|
||
display: flex;
|
||
gap: 10px;
|
||
flex-wrap: wrap;
|
||
justify-content: center;
|
||
}
|
||
.nav a {
|
||
color: white;
|
||
text-decoration: none;
|
||
padding: 10px 15px;
|
||
border-radius: 5px;
|
||
transition: all 0.3s;
|
||
font-size: 0.9em;
|
||
white-space: nowrap;
|
||
}
|
||
.nav a:hover { background: #34495e; }
|
||
.nav a.active { background: #3498db; }
|
||
.content { padding: 25px; }
|
||
|
||
.settings-section {
|
||
background: #f8f9fa;
|
||
padding: 25px;
|
||
border-radius: 10px;
|
||
margin-bottom: 20px;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||
border: 2px solid #e0e0e0;
|
||
}
|
||
|
||
.section-title {
|
||
color: #333;
|
||
font-size: 1.3em;
|
||
margin-bottom: 20px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 3px solid #667eea;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.subsection-title {
|
||
color: #555;
|
||
font-size: 1.05em;
|
||
margin: 20px 0 15px 0;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.form-group {
|
||
margin-bottom: 18px;
|
||
}
|
||
|
||
.form-group:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
label {
|
||
display: block;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-bottom: 8px;
|
||
font-size: 0.95em;
|
||
}
|
||
|
||
.help-text {
|
||
font-size: 0.85em;
|
||
color: #666;
|
||
margin-top: 5px;
|
||
line-height: 1.5;
|
||
padding-left: 5px;
|
||
}
|
||
|
||
input[type="text"],
|
||
input[type="password"] {
|
||
width: 100%;
|
||
padding: 12px 15px;
|
||
border: 2px solid #e1e8ed;
|
||
border-radius: 8px;
|
||
font-size: 0.95em;
|
||
transition: all 0.3s;
|
||
background: white;
|
||
font-family: inherit;
|
||
}
|
||
|
||
input[type="text"]:focus,
|
||
input[type="password"]:focus {
|
||
outline: none;
|
||
border-color: #667eea;
|
||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||
}
|
||
|
||
input[type="checkbox"] {
|
||
width: 20px;
|
||
height: 20px;
|
||
cursor: pointer;
|
||
margin-right: 10px;
|
||
accent-color: #667eea;
|
||
}
|
||
|
||
.checkbox-group {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: 12px;
|
||
padding: 10px;
|
||
background: white;
|
||
border-radius: 8px;
|
||
border: 2px solid #e1e8ed;
|
||
transition: all 0.3s;
|
||
}
|
||
|
||
.checkbox-group:hover {
|
||
border-color: #667eea;
|
||
}
|
||
|
||
.checkbox-group label {
|
||
margin-bottom: 0;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
flex: 1;
|
||
}
|
||
|
||
.sta-settings {
|
||
background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
|
||
padding: 20px;
|
||
border-radius: 8px;
|
||
margin-top: 15px;
|
||
border-left: 4px solid #667eea;
|
||
transition: all 0.3s;
|
||
}
|
||
|
||
.sta-settings.disabled {
|
||
opacity: 0.4;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.sta-status {
|
||
margin-top: 15px;
|
||
padding: 12px 15px;
|
||
border-radius: 8px;
|
||
font-weight: 600;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.sta-status.connected {
|
||
background: linear-gradient(135deg, rgba(17, 153, 142, 0.1) 0%, rgba(56, 239, 125, 0.1) 100%);
|
||
border: 2px solid #11998e;
|
||
color: #0d6d62;
|
||
}
|
||
|
||
.sta-status.disconnected {
|
||
background: linear-gradient(135deg, rgba(235, 51, 73, 0.1) 0%, rgba(244, 92, 67, 0.1) 100%);
|
||
border: 2px solid #eb3349;
|
||
color: #b8262f;
|
||
}
|
||
|
||
.button-group {
|
||
display: flex;
|
||
gap: 12px;
|
||
margin-top: 25px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
button {
|
||
flex: 1;
|
||
min-width: 180px;
|
||
padding: 14px 28px;
|
||
border: none;
|
||
border-radius: 8px;
|
||
font-size: 1em;
|
||
font-weight: 700;
|
||
cursor: pointer;
|
||
transition: all 0.3s;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
.btn-save {
|
||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||
color: white;
|
||
box-shadow: 0 4px 15px rgba(17, 153, 142, 0.3);
|
||
}
|
||
|
||
.btn-save:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 6px 20px rgba(17, 153, 142, 0.4);
|
||
}
|
||
|
||
.btn-cancel {
|
||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||
color: white;
|
||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
||
}
|
||
|
||
.btn-cancel:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
||
}
|
||
|
||
.btn-reboot {
|
||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||
color: white;
|
||
box-shadow: 0 4px 15px rgba(240, 147, 251, 0.3);
|
||
}
|
||
|
||
.btn-reboot:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 6px 20px rgba(240, 147, 251, 0.4);
|
||
}
|
||
|
||
button:active {
|
||
transform: translateY(0);
|
||
}
|
||
|
||
.alert {
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-bottom: 20px;
|
||
display: none;
|
||
align-items: center;
|
||
gap: 12px;
|
||
animation: slideDown 0.3s ease-out;
|
||
box-shadow: 0 3px 10px rgba(0,0,0,0.1);
|
||
}
|
||
|
||
@keyframes slideDown {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(-10px);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
|
||
.alert.show {
|
||
display: flex;
|
||
}
|
||
|
||
.alert-success {
|
||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||
color: white;
|
||
}
|
||
|
||
.alert-info {
|
||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||
color: white;
|
||
}
|
||
|
||
.alert-warning {
|
||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||
color: white;
|
||
}
|
||
|
||
.alert-icon {
|
||
font-size: 1.5em;
|
||
}
|
||
|
||
.alert-text {
|
||
flex: 1;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.info-box {
|
||
background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
|
||
border-left: 4px solid #667eea;
|
||
padding: 18px 20px;
|
||
border-radius: 8px;
|
||
margin-top: 25px;
|
||
}
|
||
|
||
.info-box-title {
|
||
font-weight: 700;
|
||
color: #333;
|
||
margin-bottom: 10px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 1.05em;
|
||
}
|
||
|
||
.info-box-text {
|
||
color: #555;
|
||
font-size: 0.9em;
|
||
line-height: 1.7;
|
||
}
|
||
|
||
.divider {
|
||
margin: 25px 0;
|
||
border: none;
|
||
border-top: 2px solid #e0e0e0;
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.content { padding: 15px; }
|
||
.settings-section { padding: 18px; }
|
||
.section-title { font-size: 1.1em; }
|
||
button { min-width: 100%; }
|
||
.button-group { flex-direction: column; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<div class="header">
|
||
<h1>⚙️ System Settings</h1>
|
||
<p>Configure WiFi, Network, and System Parameters</p>
|
||
</div>
|
||
|
||
<div class="nav">
|
||
<a href="/">📊 Monitor</a>
|
||
<a href="/transmit">📤 Transmit</a>
|
||
<a href="/graph">📈 Graph</a>
|
||
<a href="/graph-view">📊 Graph View</a>
|
||
<a href="/settings" class="active">⚙️ Settings</a>
|
||
<a href="/serial">📟 Serial</a>
|
||
</div>
|
||
|
||
<div class="content">
|
||
<div id="alert-success" class="alert alert-success">
|
||
<span class="alert-icon">✓</span>
|
||
<span class="alert-text">Settings saved successfully! Reboot to apply.</span>
|
||
</div>
|
||
|
||
<div id="alert-loading" class="alert alert-info">
|
||
<span class="alert-icon">⏳</span>
|
||
<span class="alert-text">Loading settings...</span>
|
||
</div>
|
||
|
||
<div id="alert-warning" class="alert alert-warning">
|
||
<span class="alert-icon">⚠️</span>
|
||
<span class="alert-text">Warning message</span>
|
||
</div>
|
||
|
||
<div class="settings-section">
|
||
<div class="section-title">
|
||
<span>📶</span>
|
||
<span>WiFi Configuration</span>
|
||
</div>
|
||
|
||
<div class="subsection-title">
|
||
<span>🔷</span>
|
||
<span>AP Mode (Access Point)</span>
|
||
</div>
|
||
<p style="color: #666; font-size: 0.9em; margin-bottom: 15px;">
|
||
ESP32가 생성하는 WiFi 네트워크 설정입니다. 기본적으로 항상 활성화됩니다.
|
||
</p>
|
||
|
||
<div class="form-group">
|
||
<label for="wifi-ssid">📡 AP SSID (Network Name)</label>
|
||
<input type="text" id="wifi-ssid" placeholder="Byun_CAN_Logger" maxlength="31">
|
||
<div class="help-text">WiFi 네트워크 이름 (1-31자)</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="wifi-password">🔒 AP Password</label>
|
||
<input type="password" id="wifi-password" placeholder="Minimum 8 characters" minlength="8" maxlength="63">
|
||
<div class="help-text">WiFi 비밀번호 (8-63자, 비워두면 개방 네트워크)</div>
|
||
</div>
|
||
|
||
<hr class="divider">
|
||
|
||
<div class="subsection-title">
|
||
<span>🔶</span>
|
||
<span>APSTA Mode (AP + Station)</span>
|
||
</div>
|
||
<p style="color: #666; font-size: 0.9em; margin-bottom: 15px;">
|
||
외부 WiFi 공유기에 연결하여 인터넷 접속 및 NTP 시간 동기화를 사용할 수 있습니다.
|
||
</p>
|
||
|
||
<div class="checkbox-group">
|
||
<input type="checkbox" id="sta-enable" onchange="toggleSTASettings()">
|
||
<label for="sta-enable">
|
||
<strong>Enable Station Mode</strong> - Connect to external WiFi network
|
||
</label>
|
||
</div>
|
||
|
||
<div id="sta-settings" class="sta-settings disabled">
|
||
<div class="form-group">
|
||
<label for="sta-ssid">📡 WiFi SSID to Connect</label>
|
||
<input type="text" id="sta-ssid" placeholder="Your router's WiFi name" maxlength="31">
|
||
<div class="help-text">연결할 공유기의 WiFi 이름</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="sta-password">🔒 WiFi Password</label>
|
||
<input type="password" id="sta-password" placeholder="Router password" maxlength="63">
|
||
<div class="help-text">공유기의 WiFi 비밀번호</div>
|
||
</div>
|
||
|
||
<div id="sta-status" class="sta-status disconnected" style="display: none;">
|
||
<span id="sta-status-icon">✗</span>
|
||
<div>
|
||
<div id="sta-status-text">Not connected</div>
|
||
<div id="sta-ip" style="font-size: 0.85em; opacity: 0.8; margin-top: 3px;"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="button-group">
|
||
<button class="btn-save" onclick="saveSettings()">💾 Save Settings</button>
|
||
<button class="btn-reboot" onclick="rebootDevice()">🔄 Reboot Device</button>
|
||
<button class="btn-cancel" onclick="location.href='/'">← Back</button>
|
||
</div>
|
||
|
||
<div class="info-box">
|
||
<div class="info-box-title">
|
||
<span>💡</span>
|
||
<span>Important Information</span>
|
||
</div>
|
||
<div class="info-box-text">
|
||
<strong>WiFi 설정 변경 시:</strong><br>
|
||
• 설정 저장 후 <strong>"Reboot Device"</strong> 버튼을 눌러 재부팅해야 적용됩니다.<br>
|
||
• 재부팅 시 기존 AP 연결이 끊어지므로, 새로운 SSID로 다시 접속하세요.<br><br>
|
||
|
||
<strong>APSTA 모드:</strong><br>
|
||
• Station 모드 활성화 시 ESP32가 AP와 Station을 동시에 사용합니다.<br>
|
||
• 외부 WiFi에 연결하면 NTP를 통한 자동 시간 동기화가 가능합니다.<br>
|
||
• Station 연결 실패 시에도 AP 모드는 정상 동작합니다.<br><br>
|
||
|
||
<strong>현재 접속 정보:</strong><br>
|
||
• AP IP: <strong>192.168.4.1</strong> (기본값)<br>
|
||
• WebSocket Port: <strong>81</strong><br>
|
||
• HTTP Port: <strong>80</strong>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
let ws;
|
||
|
||
function initWebSocket() {
|
||
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||
|
||
ws.onopen = function() {
|
||
console.log('✓ WebSocket connected');
|
||
loadSettings();
|
||
};
|
||
|
||
ws.onclose = function() {
|
||
console.log('✗ WebSocket disconnected');
|
||
showAlert('alert-warning', '⚠️ Connection lost. Reconnecting...', 'alert-warning');
|
||
setTimeout(initWebSocket, 3000);
|
||
};
|
||
|
||
ws.onerror = function(error) {
|
||
console.error('WebSocket error:', error);
|
||
};
|
||
|
||
ws.onmessage = function(event) {
|
||
try {
|
||
const data = JSON.parse(event.data);
|
||
|
||
if (data.type === 'settings') {
|
||
handleSettingsResponse(data);
|
||
} else if (data.type === 'settingsSaved') {
|
||
if (data.success) {
|
||
showAlert('alert-success', '✓ Settings saved! Reboot to apply changes.', 'alert-success');
|
||
} else {
|
||
showAlert('alert-warning', '✗ Failed to save settings', 'alert-warning');
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('Parse error:', e);
|
||
}
|
||
};
|
||
}
|
||
|
||
function handleSettingsResponse(data) {
|
||
document.getElementById('wifi-ssid').value = data.ssid || 'Byun_CAN_Logger';
|
||
document.getElementById('wifi-password').value = data.password || '';
|
||
|
||
document.getElementById('sta-enable').checked = data.staEnable || false;
|
||
document.getElementById('sta-ssid').value = data.staSSID || '';
|
||
document.getElementById('sta-password').value = data.staPassword || '';
|
||
|
||
toggleSTASettings();
|
||
|
||
const staStatus = document.getElementById('sta-status');
|
||
const staStatusIcon = document.getElementById('sta-status-icon');
|
||
const staStatusText = document.getElementById('sta-status-text');
|
||
const staIpElement = document.getElementById('sta-ip');
|
||
|
||
if (data.staConnected && data.staIP && data.staIP !== '0.0.0.0') {
|
||
staStatus.className = 'sta-status connected';
|
||
staStatus.style.display = 'flex';
|
||
staStatusIcon.textContent = '✓';
|
||
staStatusText.textContent = 'Connected to WiFi';
|
||
staIpElement.textContent = 'IP Address: ' + data.staIP;
|
||
} else if (data.staEnable) {
|
||
staStatus.className = 'sta-status disconnected';
|
||
staStatus.style.display = 'flex';
|
||
staStatusIcon.textContent = '✗';
|
||
staStatusText.textContent = 'Not connected (Station mode enabled)';
|
||
staIpElement.textContent = 'Check WiFi credentials';
|
||
} else {
|
||
staStatus.style.display = 'none';
|
||
}
|
||
|
||
hideAlert('alert-loading');
|
||
console.log('✓ Settings loaded:', data);
|
||
}
|
||
|
||
function loadSettings() {
|
||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||
ws.send(JSON.stringify({cmd: 'getSettings'}));
|
||
showAlert('alert-loading', '⏳ Loading settings...', 'alert-info');
|
||
}
|
||
}
|
||
|
||
function saveSettings() {
|
||
const ssid = document.getElementById('wifi-ssid').value.trim();
|
||
const password = document.getElementById('wifi-password').value;
|
||
const staEnable = document.getElementById('sta-enable').checked;
|
||
const staSSID = document.getElementById('sta-ssid').value.trim();
|
||
const staPassword = document.getElementById('sta-password').value;
|
||
|
||
// 입력 검증
|
||
if (ssid.length === 0) {
|
||
alert('⚠️ Please enter AP SSID');
|
||
return;
|
||
}
|
||
|
||
if (ssid.length > 31) {
|
||
alert('⚠️ AP SSID maximum length is 31 characters');
|
||
return;
|
||
}
|
||
|
||
if (password.length > 0 && password.length < 8) {
|
||
alert('⚠️ AP Password must be at least 8 characters (or leave empty for open network)');
|
||
return;
|
||
}
|
||
|
||
if (password.length > 63) {
|
||
alert('⚠️ AP Password maximum length is 63 characters');
|
||
return;
|
||
}
|
||
|
||
if (staEnable) {
|
||
if (staSSID.length === 0) {
|
||
alert('⚠️ Please enter Station WiFi SSID or disable Station mode');
|
||
return;
|
||
}
|
||
if (staSSID.length > 31) {
|
||
alert('⚠️ Station SSID maximum length is 31 characters');
|
||
return;
|
||
}
|
||
}
|
||
|
||
const settings = {
|
||
cmd: 'saveSettings',
|
||
ssid: ssid,
|
||
password: password,
|
||
staEnable: staEnable,
|
||
staSSID: staSSID,
|
||
staPassword: staPassword
|
||
};
|
||
|
||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||
ws.send(JSON.stringify(settings));
|
||
console.log('✓ Saving settings:', settings);
|
||
} else {
|
||
alert('⚠️ WebSocket disconnected. Please refresh the page.');
|
||
}
|
||
}
|
||
|
||
function rebootDevice() {
|
||
if (!confirm('⚠️ Reboot the device?\n\nCurrent connections will be lost.\nAfter reboot, reconnect to WiFi (use new SSID if changed).')) {
|
||
return;
|
||
}
|
||
|
||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||
ws.send(JSON.stringify({cmd: 'reboot'}));
|
||
|
||
showAlert('alert-info', '🔄 Rebooting device... Please wait 10 seconds.', 'alert-info');
|
||
|
||
setTimeout(() => {
|
||
alert('Reboot complete!\n\nIf SSID was changed, reconnect to the new network.\nThen access: http://192.168.4.1');
|
||
}, 3000);
|
||
}
|
||
}
|
||
|
||
function showAlert(alertId, message, className) {
|
||
// 모든 알림 숨김
|
||
document.querySelectorAll('.alert').forEach(alert => {
|
||
alert.classList.remove('show');
|
||
});
|
||
|
||
const alert = document.getElementById(alertId);
|
||
if (alert) {
|
||
const textElement = alert.querySelector('.alert-text');
|
||
if (textElement && message) {
|
||
textElement.textContent = message;
|
||
}
|
||
|
||
alert.className = 'alert ' + className;
|
||
alert.classList.add('show');
|
||
|
||
if (className === 'alert-success') {
|
||
setTimeout(() => {
|
||
hideAlert(alertId);
|
||
}, 5000);
|
||
}
|
||
}
|
||
}
|
||
|
||
function hideAlert(alertId) {
|
||
const alert = document.getElementById(alertId);
|
||
if (alert) {
|
||
alert.classList.remove('show');
|
||
}
|
||
}
|
||
|
||
function toggleSTASettings() {
|
||
const staEnable = document.getElementById('sta-enable').checked;
|
||
const staSettings = document.getElementById('sta-settings');
|
||
|
||
if (staEnable) {
|
||
staSettings.classList.remove('disabled');
|
||
} else {
|
||
staSettings.classList.add('disabled');
|
||
}
|
||
}
|
||
|
||
window.addEventListener('load', function() {
|
||
initWebSocket();
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|
||
)rawliteral";
|
||
|
||
#endif
|