Files
ManuelW77andClaude Opus 5 a5ba8a901a Make WiFi TX power configurable, document ESP32-S3 pins
The transmit power was hardcoded to 19.5 dBm. Some setups need a lower
value (device right next to the AP, weak 3.3V rail), so it is now a user
setting instead of a per-chip constant.

- wlan.cpp: load/save/apply TX power (0.1 dBm steps, NVS key wifi_txpwr,
  default 195), re-applied on GOT_IP so it survives a reconnect
- website.cpp: /api/wifi-power GET/POST with validation
- setup.html: "WiFi Settings" card
- README.md/README.de.md: pin table gets an ESP32-S3 column plus a warning
  that GPIO19/20 are the native USB data lines
- config.cpp: same warning next to the HX711 pin definitions

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 12:42:13 +02:00

290 lines
13 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FilaMan - Device Setup</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="fm-page">
<aside class="fm-sidebar">
<div class="sidebar-brand">
<img src="/logo.png" alt="Logo" class="sidebar-logo">
<div class="brand-text">
<h1>FilaMan <span class="version"></span></h1>
</div>
</div>
<nav class="fm-nav">
<a href="/">Start</a>
<a href="/waage">Scale</a>
<a href="/setup" class="active">Setup</a>
<a href="/upgrade">Upgrade</a>
</nav>
<div class="sidebar-status">
<div class="status-item">
<span class="status-dot" id="filamanDot"></span>
<span>System Sync</span>
</div>
<div class="status-item">
<span id="ramStatus"></span>
</div>
</div>
</aside>
<main class="fm-main">
<header>
<h1>Device Setup</h1>
<p>Register your device to connect it with your FilaMan-System account.</p>
</header>
<div class="fm-card">
<h2>System Registration</h2>
<p>Current Status: <strong style="color: var(--accent);">%registered%</strong></p>
<div class="fm-form-group" style="margin-top: 2rem;">
<label class="fm-label" for="filamanUrl">FilaMan API URL</label>
<input type="text" id="filamanUrl" class="fm-input" value="%filamanUrl%" placeholder="e.g. http://192.168.1.10:8000">
</div>
<div class="fm-form-group">
<label class="fm-label" for="deviceCode">Registration Code</label>
<input type="text" id="deviceCode" class="fm-input" maxlength="6" placeholder="6-digit code">
<p style="font-size: 0.8rem; margin-top: 0.5rem;">Enter the 6-digit code shown in your FilaMan Dashboard.</p>
</div>
<button id="registerBtn" class="fm-btn fm-btn-primary">Register Device</button>
<div id="statusMessage" style="margin-top: 1.5rem;"></div>
</div>
<div class="fm-card">
<h2>General Settings</h2>
<div class="fm-form-group" style="margin-top: 1rem;">
<label class="fm-label" for="languageSelect">Display Language</label>
<select id="languageSelect" class="fm-input">
<option value="en">English</option>
<option value="de">Deutsch</option>
</select>
</div>
</div>
<div class="fm-card">
<h2>Display Settings</h2>
<div class="fm-form-group" style="margin-top: 1rem;">
<label class="fm-label" for="sleepTimeoutSelect">OLED Sleep Timeout</label>
<select id="sleepTimeoutSelect" class="fm-input">
<option value="0">Disabled (always on)</option>
<option value="30">30 seconds</option>
<option value="60">1 minute</option>
<option value="120">2 minutes</option>
<option value="300">5 minutes</option>
<option value="600">10 minutes</option>
</select>
<p style="font-size: 0.8rem; margin-top: 0.5rem;">Display wakes automatically on weight change or NFC tag read.</p>
</div>
<div id="sleepStatusMessage" style="margin-top: 0.5rem;"></div>
</div>
<div class="fm-card">
<h2>WiFi Settings</h2>
<div class="fm-form-group" style="margin-top: 1rem;">
<label class="fm-label" for="txPowerSelect">WiFi Transmit Power</label>
<select id="txPowerSelect" class="fm-input">
<option value="195">19.5 dBm (default, maximum range)</option>
<option value="170">17 dBm</option>
<option value="150">15 dBm</option>
<option value="130">13 dBm</option>
<option value="110">11 dBm</option>
<option value="85">8.5 dBm (lowest)</option>
</select>
<p style="font-size: 0.8rem; margin-top: 0.5rem;">Only lower this if your router keeps dropping the device, or if it sits right next to the access point. Applies immediately, no restart needed.</p>
</div>
<div id="txPowerStatusMessage" style="margin-top: 0.5rem;"></div>
</div>
</main>
</div>
<script>
// Fetch Version
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) versionSpan.textContent = 'v' + data.version;
})
.catch(error => console.error('Error fetching version:', error));
// Language setting
fetch('/api/language')
.then(response => response.json())
.then(data => {
document.getElementById('languageSelect').value = data.lang;
})
.catch(error => console.error('Error fetching language:', error));
document.getElementById('languageSelect').addEventListener('change', function() {
fetch('/api/language', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ lang: this.value })
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log('Language saved');
}
})
.catch(error => console.error('Error saving language:', error));
});
// Display sleep timeout setting
fetch('/api/display')
.then(response => response.json())
.then(data => {
const sel = document.getElementById('sleepTimeoutSelect');
const val = String(data.sleepTimeout);
// Select closest matching option
let matched = false;
for (let i = 0; i < sel.options.length; i++) {
if (sel.options[i].value === val) { sel.value = val; matched = true; break; }
}
if (!matched) sel.value = '0';
})
.catch(error => console.error('Error fetching display settings:', error));
document.getElementById('sleepTimeoutSelect').addEventListener('change', function() {
const msg = document.getElementById('sleepStatusMessage');
fetch('/api/display', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sleepTimeout: parseInt(this.value) })
})
.then(response => response.json())
.then(data => {
if (data.success) {
msg.textContent = 'Saved.';
msg.style.color = 'var(--success-text)';
setTimeout(() => { msg.textContent = ''; }, 2000);
}
})
.catch(error => {
msg.textContent = 'Error saving setting.';
msg.style.color = 'var(--error-text)';
console.error('Error saving display settings:', error);
});
});
// WiFi transmit power setting
fetch('/api/wifi-power')
.then(response => response.json())
.then(data => {
const sel = document.getElementById('txPowerSelect');
const val = String(data.txPower);
let matched = false;
for (let i = 0; i < sel.options.length; i++) {
if (sel.options[i].value === val) { sel.value = val; matched = true; break; }
}
if (!matched) sel.value = '195';
})
.catch(error => console.error('Error fetching wifi power:', error));
document.getElementById('txPowerSelect').addEventListener('change', function() {
const msg = document.getElementById('txPowerStatusMessage');
fetch('/api/wifi-power', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ txPower: parseInt(this.value) })
})
.then(response => response.json())
.then(data => {
if (data.success) {
msg.textContent = 'Saved.';
msg.style.color = 'var(--success-text)';
setTimeout(() => { msg.textContent = ''; }, 2000);
} else {
msg.textContent = 'Error saving setting.';
msg.style.color = 'var(--error-text)';
}
})
.catch(error => {
msg.textContent = 'Error saving setting.';
msg.style.color = 'var(--error-text)';
console.error('Error saving wifi power:', error);
});
});
document.getElementById('registerBtn').addEventListener('click', () => {
const url = document.getElementById('filamanUrl').value;
const code = document.getElementById('deviceCode').value;
const statusMessage = document.getElementById('statusMessage');
if (!url || !code) {
statusMessage.textContent = 'Please provide both URL and Code';
statusMessage.style.color = 'var(--error-text)';
return;
}
statusMessage.textContent = 'Registering device...';
statusMessage.style.color = 'var(--text-muted)';
fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: url, code: code })
})
.then(response => response.json())
.then(data => {
if (data.success) {
// 202 Accepted: Registrierung wurde nur eingereiht. Das
// tatsaechliche Ergebnis kommt per WebSocket ('registerResult').
statusMessage.textContent = 'Registering device...';
statusMessage.style.color = 'var(--text-muted)';
} else {
statusMessage.textContent = 'Registration failed. Please check your code and URL.';
statusMessage.style.color = 'var(--error-text)';
}
})
.catch(error => {
console.error('Error:', error);
statusMessage.textContent = 'Network error. Please check connection.';
statusMessage.style.color = 'var(--error-text)';
});
});
// WebSocket handling
let ws = null;
function connectWebSocket() {
ws = new WebSocket(`ws://${window.location.hostname}/ws`);
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'heartbeat') {
const dot = document.getElementById('filamanDot');
dot.className = data.filaman_connected ? 'status-dot online' : 'status-dot offline';
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
}
else if (data.type === 'registerResult') {
// Die Registrierung laeuft asynchron im API-Task; /api/register
// antwortet sofort mit 202, das Ergebnis kommt hier an.
const statusMessage = document.getElementById('statusMessage');
if (data.success) {
statusMessage.textContent = 'Registration successful!';
statusMessage.style.color = 'var(--success-text)';
setTimeout(() => location.reload(), 2000);
} else {
statusMessage.textContent = 'Registration failed. Please check your code and URL.';
statusMessage.style.color = 'var(--error-text)';
}
}
};
ws.onclose = () => setTimeout(connectWebSocket, 2000);
}
connectWebSocket();
setInterval(() => { if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({type:'heartbeat'})); }, 5000);
</script>
</body>
</html>