refactor: Fixed the file hierarchy and switched to platform.io

This commit is contained in:
2026-02-28 21:57:42 +02:00
parent ab1e4f2e6d
commit 30d660268f
65 changed files with 1208 additions and 1281 deletions
+281
View File
@@ -0,0 +1,281 @@
/*
* ═══════════════════════════════════════════════════════════════════════════════════
* SETTINGSPAGE.H - HTML Content for Settings Web Interface
* ═══════════════════════════════════════════════════════════════════════════════════
*
* This file contains the HTML/CSS/JavaScript for the VESPER network settings page.
* Separated from the main implementation for better maintainability.
*
* 📋 VERSION: 1.0
* 📅 DATE: 2025-12-29
* 👨‍💻 AUTHOR: Advanced Bell Systems
* ═══════════════════════════════════════════════════════════════════════════════════
*/
#pragma once
// HTML template for the settings page
// Use placeholders for dynamic content:
// %MODE_BADGE_CLASS% - "ap" or "station"
// %MODE_TEXT% - "AP Mode" or "Station Mode"
// %CURRENT_IP% - Current IP address
// %DEVICE_UID% - Device unique ID
// %FW_VERSION% - Firmware version
// %AP_ACTIVE_CLASS% - "active" if in AP mode, "" otherwise
// %STATION_ACTIVE_CLASS% - "active" if in station mode, "" otherwise
// %SELECTED_MODE% - "ap" or "station"
const char SETTINGS_PAGE_HTML[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VESPER Network Settings</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;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
padding: 40px;
max-width: 500px;
width: 100%;
}
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
color: #667eea;
font-size: 32px;
margin-bottom: 10px;
}
.header p {
color: #666;
font-size: 14px;
}
.status-card {
background: #f8f9fa;
border-radius: 12px;
padding: 20px;
margin-bottom: 30px;
}
.status-item {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
font-size: 14px;
}
.status-item:last-child {
margin-bottom: 0;
}
.status-label {
color: #666;
font-weight: 500;
}
.status-value {
color: #333;
font-weight: 600;
}
.mode-badge {
display: inline-block;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
}
.mode-badge.ap {
background: #e3f2fd;
color: #1976d2;
}
.mode-badge.station {
background: #e8f5e9;
color: #388e3c;
}
.section-title {
font-size: 18px;
color: #333;
margin-bottom: 20px;
font-weight: 600;
}
.mode-selector {
display: flex;
gap: 15px;
margin-bottom: 30px;
}
.mode-option {
flex: 1;
background: #f8f9fa;
border: 2px solid #e0e0e0;
border-radius: 12px;
padding: 20px;
cursor: pointer;
transition: all 0.3s ease;
text-align: center;
}
.mode-option:hover {
border-color: #667eea;
background: #f0f4ff;
}
.mode-option.active {
border-color: #667eea;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.mode-option h3 {
font-size: 16px;
margin-bottom: 8px;
}
.mode-option p {
font-size: 12px;
opacity: 0.8;
}
.btn {
width: 100%;
padding: 15px;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin-bottom: 10px;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
.btn-secondary {
background: #f8f9fa;
color: #666;
}
.btn-secondary:hover {
background: #e9ecef;
}
.info-box {
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
font-size: 13px;
color: #856404;
}
.footer {
text-align: center;
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #e0e0e0;
color: #999;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>VESPER Settings</h1>
<p>Network Configuration</p>
</div>
<div class="status-card">
<div class="status-item">
<span class="status-label">Current Mode:</span>
<span class="status-value">
<span class="mode-badge %MODE_BADGE_CLASS%">
%MODE_TEXT%
</span>
</span>
</div>
<div class="status-item">
<span class="status-label">IP Address:</span>
<span class="status-value">%CURRENT_IP%</span>
</div>
<div class="status-item">
<span class="status-label">Device UID:</span>
<span class="status-value">%DEVICE_UID%</span>
</div>
<div class="status-item">
<span class="status-label">Firmware:</span>
<span class="status-value">v%FW_VERSION%</span>
</div>
</div>
<div class="section-title">Select Network Mode</div>
<div class="mode-selector">
<div class="mode-option %AP_ACTIVE_CLASS%" onclick="selectMode('ap')">
<h3>AP Mode</h3>
<p>Direct Connection<br>192.168.4.1</p>
</div>
<div class="mode-option %STATION_ACTIVE_CLASS%" onclick="selectMode('station')">
<h3>Router Mode</h3>
<p>Connect via Router<br>WiFi/Ethernet</p>
</div>
</div>
<button class="btn btn-primary" onclick="applyMode()">Apply & Reboot</button>
<button class="btn btn-secondary" onclick="rebootDevice()">Reboot Device</button>
<div class="info-box">
Device will reboot after applying changes. Make sure to reconnect to the correct network after reboot.
</div>
<div class="footer">
VESPER Bell Automation System<br>
Advanced Bell Systems
</div>
</div>
<script>
let selectedMode = '%SELECTED_MODE%';
function selectMode(mode) {
selectedMode = mode;
document.querySelectorAll('.mode-option').forEach(el => {
el.classList.remove('active');
});
event.target.closest('.mode-option').classList.add('active');
}
function applyMode() {
if (confirm('Device will reboot and switch to ' + (selectedMode === 'ap' ? 'AP Mode' : 'Router Mode') + '. Continue?')) {
fetch('/api/set-mode', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: 'mode=' + selectedMode
}).then(response => {
alert('Rebooting... Please wait 10 seconds and reconnect.');
});
}
}
function rebootDevice() {
if (confirm('Reboot device now?')) {
fetch('/api/reboot', {method: 'POST'}).then(() => {
alert('Rebooting... Please wait 10 seconds.');
});
}
}
</script>
</body>
</html>
)rawliteral";
+126
View File
@@ -0,0 +1,126 @@
/*
* ═══════════════════════════════════════════════════════════════════════════════════
* SETTINGSWEBSERVER.CPP - Network Mode Settings Web Interface Implementation
* ═══════════════════════════════════════════════════════════════════════════════════
*/
#include "SettingsWebServer.hpp"
#define TAG "SettingsWebServer"
#include "SettingsPage.h"
#include "../ConfigManager/ConfigManager.hpp"
#include "../Networking/Networking.hpp"
#include "../Logging/Logging.hpp"
SettingsWebServer::SettingsWebServer(AsyncWebServer& server,
ConfigManager& configManager,
Networking& networking)
: _server(server)
, _configManager(configManager)
, _networking(networking) {
}
SettingsWebServer::~SettingsWebServer() {
}
void SettingsWebServer::begin() {
LOG_INFO(TAG, "SettingsWebServer - Initializing settings web interface");
// GET /settings - Main settings page
_server.on("/settings", HTTP_GET,
[this](AsyncWebServerRequest* request) {
handleSettingsPage(request);
}
);
// POST /api/set-mode - Set network mode
_server.on("/api/set-mode", HTTP_POST,
[this](AsyncWebServerRequest* request) {
handleSetMode(request);
}
);
// POST /api/reboot - Reboot device
_server.on("/api/reboot", HTTP_POST,
[this](AsyncWebServerRequest* request) {
handleReboot(request);
}
);
LOG_INFO(TAG, "SettingsWebServer - Endpoints registered");
LOG_INFO(TAG, " GET /settings - Settings page");
LOG_INFO(TAG, " POST /api/set-mode - Set network mode");
LOG_INFO(TAG, " POST /api/reboot - Reboot device");
}
void SettingsWebServer::handleSettingsPage(AsyncWebServerRequest* request) {
LOG_DEBUG(TAG, "SettingsWebServer - Settings page requested");
String html = generateSettingsHTML();
request->send(200, "text/html", html);
}
void SettingsWebServer::handleSetMode(AsyncWebServerRequest* request) {
if (!request->hasParam("mode", true)) {
request->send(400, "text/plain", "Missing mode parameter");
return;
}
String mode = request->getParam("mode", true)->value();
LOG_INFO(TAG, "SettingsWebServer - Mode change requested: %s", mode.c_str());
if (mode == "ap") {
// Switch to permanent AP mode
_configManager.setPermanentAPMode(true);
_configManager.saveNetworkConfig();
LOG_INFO(TAG, "✅ Permanent AP mode enabled - will activate on reboot");
request->send(200, "text/plain", "AP mode enabled. Device will reboot in 3 seconds.");
// Reboot after 3 seconds
delay(3000);
ESP.restart();
} else if (mode == "station") {
// Switch to station mode (router mode)
_configManager.setPermanentAPMode(false);
_configManager.saveNetworkConfig();
LOG_INFO(TAG, "✅ Station mode enabled - will activate on reboot");
request->send(200, "text/plain", "Station mode enabled. Device will reboot in 3 seconds.");
// Reboot after 3 seconds
delay(3000);
ESP.restart();
} else {
request->send(400, "text/plain", "Invalid mode. Use 'ap' or 'station'");
}
}
void SettingsWebServer::handleReboot(AsyncWebServerRequest* request) {
LOG_INFO(TAG, "SettingsWebServer - Reboot requested");
request->send(200, "text/plain", "Rebooting device in 2 seconds...");
delay(2000);
ESP.restart();
}
String SettingsWebServer::generateSettingsHTML() {
bool isAPMode = _networking.isInAPMode();
String currentIP = _networking.getLocalIP();
String deviceUID = _configManager.getDeviceUID();
String fwVersion = _configManager.getFwVersion();
// Load HTML template from PROGMEM
String html = String(FPSTR(SETTINGS_PAGE_HTML));
// Replace placeholders with dynamic values
html.replace("%MODE_BADGE_CLASS%", isAPMode ? "ap" : "station");
html.replace("%MODE_TEXT%", isAPMode ? "AP Mode" : "Station Mode");
html.replace("%CURRENT_IP%", currentIP);
html.replace("%DEVICE_UID%", deviceUID);
html.replace("%FW_VERSION%", fwVersion);
html.replace("%AP_ACTIVE_CLASS%", isAPMode ? "active" : "");
html.replace("%STATION_ACTIVE_CLASS%", !isAPMode ? "active" : "");
html.replace("%SELECTED_MODE%", isAPMode ? "ap" : "station");
return html;
}
@@ -0,0 +1,66 @@
/*
* ═══════════════════════════════════════════════════════════════════════════════════
* SETTINGSWEBSERVER.HPP - Network Mode Settings Web Interface
* ═══════════════════════════════════════════════════════════════════════════════════
*
* 🌐 SETTINGS WEB INTERFACE FOR VESPER 🌐
*
* Provides web interface for switching between AP and Station modes:
* • Accessible at http://192.168.4.1/settings (AP mode)
* • Accessible at http://{device-ip}/settings (Station mode)
* • Toggle between AP mode and Router mode
* • Configure WiFi credentials for router connection
* • Reboot device with new settings
*
* 🏗️ ARCHITECTURE:
* • Uses AsyncWebServer for non-blocking operation
* • HTML interface with toggle switch
* • Updates ConfigManager and triggers reboot
* • Works in both AP and Station modes
*
* 📡 ENDPOINTS:
* GET /settings - Settings page with mode toggle
* POST /api/set-mode - Set network mode (AP or STA)
* POST /api/reboot - Reboot device
*
* 📋 VERSION: 1.0
* 📅 DATE: 2025-12-28
* 👨‍💻 AUTHOR: Advanced Bell Systems
* ═══════════════════════════════════════════════════════════════════════════════════
*/
#pragma once
#include <Arduino.h>
#include <ESPAsyncWebServer.h>
// Forward declarations
class ConfigManager;
class Networking;
class SettingsWebServer {
public:
explicit SettingsWebServer(AsyncWebServer& server,
ConfigManager& configManager,
Networking& networking);
~SettingsWebServer();
/**
* @brief Initialize settings web server and register endpoints
*/
void begin();
private:
// Dependencies
AsyncWebServer& _server;
ConfigManager& _configManager;
Networking& _networking;
// Endpoint handlers
void handleSettingsPage(AsyncWebServerRequest* request);
void handleSetMode(AsyncWebServerRequest* request);
void handleReboot(AsyncWebServerRequest* request);
// HTML generation
String generateSettingsHTML();
};