Files
2025-12-08 21:10:33 +00:00

626 lines
21 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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</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: 800px;
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: #666;
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: #f8f9fa;
padding: 0;
border-bottom: 2px solid #e0e0e0;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.nav a {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 15px 20px;
text-decoration: none;
color: #666;
font-weight: 500;
font-size: 0.95em;
border-bottom: 3px solid transparent;
transition: all 0.3s;
white-space: nowrap;
min-width: 120px;
}
.nav a:hover {
background: #e9ecef;
color: #667eea;
transform: translateY(-2px);
}
.nav a.active {
color: #764ba2;
border-bottom-color: #764ba2;
background: white;
font-weight: 600;
}
.content { padding: 30px; }
.settings-section {
background: #f8f9fa;
padding: 25px;
border-radius: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.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;
}
.form-group {
margin-bottom: 20px;
}
.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.4;
}
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;
}
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;
}
.checkbox-group {
display: flex;
align-items: center;
margin-bottom: 15px;
}
.checkbox-group label {
margin-bottom: 0;
cursor: pointer;
user-select: none;
}
.sta-settings {
background: #f0f4f8;
padding: 20px;
border-radius: 8px;
margin-top: 15px;
border-left: 4px solid #667eea;
}
.sta-settings.disabled {
opacity: 0.5;
pointer-events: none;
}
.button-group {
display: flex;
gap: 15px;
margin-top: 30px;
flex-wrap: wrap;
}
button {
flex: 1;
min-width: 150px;
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: #666;
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: #666;
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);
}
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;
}
@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: #666;
}
.alert-info {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #666;
}
.alert-warning {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
color: #666;
}
.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: 15px 20px;
border-radius: 8px;
margin-top: 15px;
}
.info-box-title {
font-weight: 700;
color: #333;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.info-box-text {
color: #555;
font-size: 0.9em;
line-height: 1.6;
}
/* ========== 반응형 디자인 ========== */
@media (max-width: 768px) {
body {
padding: 5px;
}
.container {
border-radius: 10px;
}
.header {
padding: 15px;
flex-direction: column;
text-align: center;
gap: 10px;
}
.header h1 {
font-size: 1.4em;
}
.nav {
padding: 5px;
}
.nav a {
padding: 12px 15px;
font-size: 0.85em;
}
.content {
padding: 15px;
}
.btn {
padding: 10px 20px;
font-size: 13px;
}
}
@media (min-width: 769px) and (max-width: 1024px) {
.header h1 {
font-size: 1.6em;
}
.nav a {
padding: 13px 18px;
font-size: 0.9em;
}
.content {
padding: 25px;
}
}
@media (min-width: 1025px) {
.content {
padding: 30px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1> Settings</h1>
<p>Configure WiFi and System Settings</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">📟 Serial1</a>
<a href="/serial2">📟 Serial2</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!</span>
</div>
<div id="alert-loading" class="alert alert-info">
<span class="alert-icon">⏳</span>
<span class="alert-text">Loading settings...</span>
</div>
<div class="settings-section">
<div class="section-title">
<span>📶</span>
<span>WiFi Configuration</span>
</div>
<h3 style="color: #333; font-size: 1.1em; margin-bottom: 15px;">AP Mode (Access Point)</h3>
<div class="form-group">
<label for="wifi-ssid">AP SSID ( )</label>
<input type="text" id="wifi-ssid" placeholder="Byun_CAN_Logger" maxlength="31">
<div class="help-text">ESP32가 생성할 WiFi 네트워크 이름입니다 (최대 31자)</div>
</div>
<div class="form-group">
<label for="wifi-password">AP Password ()</label>
<input type="password" id="wifi-password" placeholder="최소 8자 이상" minlength="8" maxlength="63">
<div class="help-text">WiFi 접속 시 필요한 비밀번호입니다 (8-63자)</div>
</div>
<hr style="margin: 25px 0; border: none; border-top: 1px solid #ddd;">
<h3 style="color: #333; font-size: 1.1em; margin-bottom: 15px;">APSTA Mode (AP + Station)</h3>
<div class="checkbox-group">
<input type="checkbox" id="sta-enable" onchange="toggleSTASettings()">
<label for="sta-enable">Station ( WiFi에 )</label>
</div>
<div class="help-text" style="margin-left: 30px; margin-bottom: 15px;">
AP와 Station을
</div>
<div id="sta-settings" class="sta-settings disabled">
<div class="form-group">
<label for="sta-ssid"> WiFi SSID</label>
<input type="text" id="sta-ssid" placeholder="공유기 이름 입력" 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="공유기 비밀번호 입력" maxlength="63">
<div class="help-text">외부 WiFi 비밀번호</div>
</div>
<div id="sta-status" style="display: none; margin-top: 15px; padding: 12px; background: #e8f5e9; border-radius: 6px; color: #2e7d32; font-weight: 600;">
WiFi : <span id="sta-ip"></span>
</div>
</div>
</div>
<div class="button-group">
<button class="btn-save" onclick="saveSettings()">💾 Save Settings</button>
<button class="btn-cancel" onclick="location.href='/'">← Back to Monitor</button>
</div>
<div class="info-box" style="margin-top: 30px;">
<div class="info-box-title">
<span></span>
<span> </span>
</div>
<div class="info-box-text">
WiFi , ESP32를 SSID/ .<br>
<strong>APSTA :</strong> Station ESP32가 AP와 Station을 .<br>
Station WiFi에 .<br>
Station AP .<br>
ESP32의 .
</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-loading', ' . ...', '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') {
document.getElementById('wifi-ssid').value = data.ssid || 'Byun_CAN_Logger';
document.getElementById('wifi-password').value = data.password || '';
// STA 모드 설정 로드
document.getElementById('sta-enable').checked = data.staEnable || false;
document.getElementById('sta-ssid').value = data.staSSID || '';
document.getElementById('sta-password').value = data.staPassword || '';
// STA 설정 표시/숨김
toggleSTASettings();
// STA 연결 상태 표시
if (data.staConnected && data.staIP && data.staIP !== '0.0.0.0') {
document.getElementById('sta-ip').textContent = data.staIP;
document.getElementById('sta-status').style.display = 'block';
} else {
document.getElementById('sta-status').style.display = 'none';
}
hideAlert('alert-loading');
console.log('Settings loaded:', data);
} else if (data.type === 'settingsSaved') {
if (data.success) {
showAlert('alert-success', ' ! .', 'alert-success');
}
}
} catch (e) {
console.error('Parse error:', e);
}
};
}
function loadSettings() {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({cmd: 'getSettings'}));
showAlert('alert-loading', ' ...', 'alert-info');
}
}
function saveSettings() {
const ssid = document.getElementById('wifi-ssid').value.trim();
const password = document.getElementById('wifi-password').value;
// STA 모드 설정
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('WiFi SSID를 .');
return;
}
if (ssid.length > 31) {
alert('WiFi SSID는 31 .');
return;
}
if (password.length > 0 && password.length < 8) {
alert('WiFi 8 .');
return;
}
if (password.length > 63) {
alert('WiFi 63 .');
return;
}
// STA 모드 검증
if (staEnable) {
if (staSSID.length === 0) {
alert('Station WiFi SSID를 .');
return;
}
if (staSSID.length > 31) {
alert('Station WiFi SSID는 31 .');
return;
}
if (staPassword.length > 0 && staPassword.length < 8) {
alert('Station WiFi 8 .');
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('Settings saved:', settings);
} else {
alert('WebSocket . .');
}
}
function showAlert(alertId, message, className) {
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');
// 3초 후 자동 숨김 (success 알림만)
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');
}
}
// 페이지 로드 시 WebSocket 연결
window.addEventListener('load', function() {
initWebSocket();
});
</script>
</body>
</html>
)rawliteral";
#endif