550 lines
20 KiB
C
550 lines
20 KiB
C
#ifndef CANFD_SETTINGS_H
|
||
#define CANFD_SETTINGS_H
|
||
|
||
const char canfd_settings_html[] PROGMEM = R"rawliteral(
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Settings - ESP32-S3 CAN FD 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: white;
|
||
padding: 20px;
|
||
text-align: center;
|
||
}
|
||
.header h1 { font-size: 28px; margin-bottom: 5px; }
|
||
.header p { opacity: 0.9; font-size: 14px; }
|
||
|
||
/* Navigation */
|
||
.nav {
|
||
background: #f8f9fa;
|
||
padding: 0;
|
||
border-bottom: 2px solid #e0e0e0;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
justify-content: center;
|
||
}
|
||
.nav a {
|
||
padding: 15px 20px;
|
||
text-decoration: none;
|
||
color: #666;
|
||
font-weight: 500;
|
||
font-size: 14px;
|
||
border-bottom: 3px solid transparent;
|
||
transition: all 0.3s;
|
||
}
|
||
.nav a:hover {
|
||
background: #e9ecef;
|
||
color: #667eea;
|
||
}
|
||
.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: 20px;
|
||
margin-bottom: 20px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 3px solid #667eea;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.form-group {
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
label {
|
||
display: block;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-bottom: 8px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.help-text {
|
||
font-size: 12px;
|
||
color: #666;
|
||
margin-top: 5px;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
input[type="text"],
|
||
input[type="password"],
|
||
select {
|
||
width: 100%;
|
||
padding: 12px 15px;
|
||
border: 2px solid #e1e8ed;
|
||
border-radius: 8px;
|
||
font-size: 14px;
|
||
transition: all 0.3s;
|
||
background: white;
|
||
}
|
||
|
||
input:focus, select: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;
|
||
}
|
||
|
||
.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: 14px;
|
||
font-weight: 700;
|
||
cursor: pointer;
|
||
transition: all 0.3s;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.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);
|
||
}
|
||
|
||
.alert {
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-bottom: 20px;
|
||
display: none;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.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-icon {
|
||
font-size: 20px;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.info-box-text {
|
||
color: #555;
|
||
font-size: 13px;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.sta-status {
|
||
margin-top: 15px;
|
||
padding: 12px;
|
||
background: #e8f5e9;
|
||
border-radius: 6px;
|
||
color: #2e7d32;
|
||
font-weight: 600;
|
||
display: none;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="container">
|
||
<div class="header">
|
||
<h1>⚙️ Settings</h1>
|
||
<p>Configure WiFi and CAN Settings</p>
|
||
</div>
|
||
|
||
<div class="nav">
|
||
<a href="/">📊 Dashboard</a>
|
||
<a href="/settings" class="active">⚙️ Settings</a>
|
||
<a href="/graph">📈 Graph</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>
|
||
|
||
<!-- WiFi Settings -->
|
||
<div class="settings-section">
|
||
<div class="section-title">
|
||
<span>📶</span>
|
||
<span>WiFi Configuration</span>
|
||
</div>
|
||
|
||
<h3 style="color: #333; font-size: 16px; 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_CANFD_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: 16px; 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" class="sta-status">
|
||
✓ WiFi 연결됨: <span id="sta-ip"></span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- CAN Settings -->
|
||
<div class="settings-section">
|
||
<div class="section-title">
|
||
<span>🚗</span>
|
||
<span>CAN Configuration</span>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="can-mode">CAN Mode</label>
|
||
<select id="can-mode" onchange="toggleDataRate()">
|
||
<option value="fd">CAN FD Mode</option>
|
||
<option value="classic">Classic CAN Mode</option>
|
||
</select>
|
||
<div class="help-text">CAN FD: 최대 64바이트, Classic CAN: 최대 8바이트</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="bit-rate">Arbitration Bit Rate</label>
|
||
<select id="bit-rate">
|
||
<option value="125000">125 kbps</option>
|
||
<option value="250000">250 kbps</option>
|
||
<option value="500000" selected>500 kbps</option>
|
||
<option value="1000000">1 Mbps</option>
|
||
</select>
|
||
<div class="help-text">CAN 버스 속도</div>
|
||
</div>
|
||
|
||
<div class="form-group" id="data-rate-group">
|
||
<label for="data-rate">Data Rate Factor (CAN FD만)</label>
|
||
<select id="data-rate">
|
||
<option value="1">x1</option>
|
||
<option value="2">x2</option>
|
||
<option value="4" selected>x4 (권장)</option>
|
||
<option value="8">x8</option>
|
||
</select>
|
||
<div class="help-text">CAN FD 데이터 구간 속도 배율</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label for="controller-mode">Controller Mode</label>
|
||
<select id="controller-mode">
|
||
<option value="0" selected>Normal</option>
|
||
<option value="1">Listen Only</option>
|
||
<option value="2">Loopback</option>
|
||
</select>
|
||
<div class="help-text">Normal: 일반 통신, Listen Only: 수신 전용</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 Dashboard</button>
|
||
</div>
|
||
|
||
<div class="info-box">
|
||
<div class="info-box-title">
|
||
⚠️ 중요 안내
|
||
</div>
|
||
<div class="info-box-text">
|
||
• WiFi 설정을 변경한 경우, <strong>ESP32를 재부팅</strong>해야 새 SSID/비밀번호가 적용됩니다.<br>
|
||
• <strong>APSTA 모드:</strong> Station 모드를 활성화하면 ESP32가 AP와 Station을 동시에 사용합니다.<br>
|
||
• Station 모드로 외부 WiFi에 연결하면 인터넷 접속이 가능해집니다.<br>
|
||
• Station 연결 실패 시에도 AP 모드는 정상 동작합니다.<br>
|
||
• CAN 설정 변경 후에도 <strong>ESP32 재부팅</strong>이 필요합니다.<br>
|
||
• 설정 저장 후 ESP32의 <strong>RST 버튼</strong>을 눌러 재부팅하세요.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
function loadSettings() {
|
||
fetch('/settings/get')
|
||
.then(r => r.json())
|
||
.then(data => {
|
||
// WiFi settings
|
||
document.getElementById('wifi-ssid').value = data.wifiSSID || 'Byun_CANFD_Logger';
|
||
document.getElementById('wifi-password').value = data.wifiPassword || '';
|
||
|
||
// STA settings
|
||
document.getElementById('sta-enable').checked = data.staEnable || false;
|
||
document.getElementById('sta-ssid').value = data.staSSID || '';
|
||
document.getElementById('sta-password').value = data.staPassword || '';
|
||
|
||
// CAN settings
|
||
document.getElementById('can-mode').value = data.canMode || 'fd';
|
||
document.getElementById('bit-rate').value = data.bitRate || 500000;
|
||
document.getElementById('data-rate').value = data.dataRate || 4;
|
||
document.getElementById('controller-mode').value = data.controllerMode || 0;
|
||
|
||
// Update UI
|
||
toggleSTASettings();
|
||
toggleDataRate();
|
||
|
||
// STA status
|
||
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');
|
||
})
|
||
.catch(err => {
|
||
console.error('Failed to load settings:', err);
|
||
hideAlert('alert-loading');
|
||
});
|
||
}
|
||
|
||
function saveSettings() {
|
||
const settings = {
|
||
wifiSSID: document.getElementById('wifi-ssid').value.trim(),
|
||
wifiPassword: document.getElementById('wifi-password').value,
|
||
staEnable: document.getElementById('sta-enable').checked,
|
||
staSSID: document.getElementById('sta-ssid').value.trim(),
|
||
staPassword: document.getElementById('sta-password').value,
|
||
canMode: document.getElementById('can-mode').value,
|
||
bitRate: parseInt(document.getElementById('bit-rate').value),
|
||
dataRate: parseInt(document.getElementById('data-rate').value),
|
||
controllerMode: parseInt(document.getElementById('controller-mode').value)
|
||
};
|
||
|
||
// Validation
|
||
if (settings.wifiSSID.length === 0) {
|
||
alert('WiFi SSID를 입력하세요.');
|
||
return;
|
||
}
|
||
|
||
if (settings.wifiPassword.length > 0 && settings.wifiPassword.length < 8) {
|
||
alert('WiFi 비밀번호는 최소 8자 이상이어야 합니다.');
|
||
return;
|
||
}
|
||
|
||
if (settings.staEnable && settings.staSSID.length === 0) {
|
||
alert('Station 모드를 활성화하려면 WiFi SSID를 입력하세요.');
|
||
return;
|
||
}
|
||
|
||
fetch('/settings/save', {
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/json'},
|
||
body: JSON.stringify(settings)
|
||
})
|
||
.then(r => r.json())
|
||
.then(data => {
|
||
if (data.success) {
|
||
showAlert('alert-success', '설정이 저장되었습니다! ESP32를 재부팅하세요.', 'alert-success');
|
||
} else {
|
||
alert('설정 저장 실패: ' + data.message);
|
||
}
|
||
})
|
||
.catch(err => {
|
||
alert('설정 저장 실패: ' + err);
|
||
});
|
||
}
|
||
|
||
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');
|
||
}
|
||
}
|
||
|
||
function toggleDataRate() {
|
||
const canMode = document.getElementById('can-mode').value;
|
||
const dataRateGroup = document.getElementById('data-rate-group');
|
||
|
||
if (canMode === 'classic') {
|
||
dataRateGroup.style.display = 'none';
|
||
} else {
|
||
dataRateGroup.style.display = 'block';
|
||
}
|
||
}
|
||
|
||
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');
|
||
|
||
if (className === 'alert-success') {
|
||
setTimeout(() => {
|
||
hideAlert(alertId);
|
||
}, 5000);
|
||
}
|
||
}
|
||
}
|
||
|
||
function hideAlert(alertId) {
|
||
const alert = document.getElementById(alertId);
|
||
if (alert) {
|
||
alert.classList.remove('show');
|
||
}
|
||
}
|
||
|
||
// Load settings on page load
|
||
window.addEventListener('load', function() {
|
||
showAlert('alert-loading', '설정을 불러오는 중...', 'alert-info');
|
||
loadSettings();
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|
||
)rawliteral";
|
||
|
||
#endif |