Ajout partie Web

This commit is contained in:
2026-02-23 10:53:32 +01:00
parent b891c12400
commit c0d50a20ba
11 changed files with 346 additions and 28 deletions

View File

@@ -5,6 +5,7 @@
#include "WiFiManagerHelper.h"
#include "main.h"
#include <ESP8266WebServer.h>
#include <LittleFS.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
@@ -23,34 +24,56 @@ Adafruit_SSD1306 *display;
// Create web server instance on port 80
ESP8266WebServer server(80);
// HTML content for welcome page
const char* welcome_html = R"HTML(
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>Welcome to ESP8266 DCC Command Station</title>
<style>
body { font-family: Arial, sans-serif; background: #f4f4f4; color: #333; margin: 0; padding: 0; }
.container { max-width: 600px; margin: 40px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 32px; }
h1 { color: #0077cc; }
p { font-size: 1.2em; }
</style>
</head>
<body>
<div class=\"container\">
<h1>Welcome!</h1>
<p>This is your ESP8266 DCC Command Station.</p>
<p>Configure WiFi, manage XpressNet, and control your layout from here.</p>
<p>For documentation, see <a href=\"/xpressnet.md\">XpressNet Commands</a> and <a href=\"/README.md\">Hardware Setup</a>.</p>
</div>
</body>
</html>
)HTML";
// // HTML content for welcome page
// const char* welcome_html = R"HTML(
// <!DOCTYPE html>
// <html lang=\"en\">
// <head>
// <meta charset=\"UTF-8\">
// <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
// <title>Welcome to ESP8266 DCC Command Station</title>
// <style>
// body { font-family: Arial, sans-serif; background: #f4f4f4; color: #333; margin: 0; padding: 0; }
// .container { max-width: 600px; margin: 40px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 32px; }
// h1 { color: #0077cc; }
// p { font-size: 1.2em; }
// </style>
// </head>
// <body>
// <div class=\"container\">
// <h1>Welcome!</h1>
// <p>This is your ESP8266 DCC Command Station.</p>
// <p>Configure WiFi, manage XpressNet, and control your layout from here.</p>
// <p>For documentation, see <a href=\"/xpressnet.md\">XpressNet Commands</a> and <a href=\"/README.md\">Hardware Setup</a>.</p>
// </div>
// </body>
// </html>
// )HTML";
void handleWelcome() {
server.send(200, "text/html", welcome_html);
if (LittleFS.exists("/index.html")) {
File file = LittleFS.open("/index.html", "r");
if (file) {
String html = file.readString();
server.send(200, "text/html", html);
file.close();
return;
}
}
server.send(404, "text/plain", "Welcome page not found");
}
void handleXpressNetPage() {
if (LittleFS.exists("/xpressnet.html")) {
File file = LittleFS.open("/xpressnet.html", "r");
if (file) {
String html = file.readString();
server.send(200, "text/html", html);
file.close();
return;
}
}
server.send(404, "text/plain", "XpressNet page not found");
}
void setup() {
@@ -60,7 +83,32 @@ void setup() {
displayInit();
Serial.println("[DEBUG] OLED display initialized");
setupWiFiManager();
if (!LittleFS.begin()) {
Serial.println("[ERROR] LittleFS mount failed");
while(true) {
display->clearDisplay();
display->setTextSize(1);
display->setTextColor(SSD1306_WHITE);
display->setCursor(0, 0);
display->println("LittleFS Mount Failed!");
display->display();
delay(1000);
}
} else {
Serial.println("[DEBUG] LittleFS mounted");
// List files in LittleFS root for debug
// Serial.println("[DEBUG] LittleFS root directory:");
// Dir dir = LittleFS.openDir("/");
// while (dir.next()) {
// Serial.print(" ");
// Serial.print(dir.fileName());
// Serial.print(" (size: ");
// Serial.print(dir.fileSize());
// Serial.println(")");
// }
}
server.on("/", handleWelcome);
server.on("/xpressnet.html", handleXpressNetPage);
server.begin();
Serial.println("[DEBUG] Web server started");
}