diff --git a/data/index.html b/data/index.html index 05cae7b..cb31b54 100644 --- a/data/index.html +++ b/data/index.html @@ -15,9 +15,10 @@

ESP8266 DCC Command Station

This is your ESP8266 DCC Command Station.

+

Pilotage train ici.

Configure WiFi, manage XpressNet, and control your layout from here.

-

For documentation, see XpressNet Commands and Hardware Setup.

+

For documentation, see XpressNet Commands + and Hardware Setup.

diff --git a/src/WebServer.cpp b/src/WebServer.cpp new file mode 100644 index 0000000..a419862 --- /dev/null +++ b/src/WebServer.cpp @@ -0,0 +1,18 @@ +#include +#include +#include "main.h" +#include "WebServer.h" + + +void handlePage(char *page) { + if (LittleFS.exists(page)) { + File file = LittleFS.open(page, "r"); + if (file) { + String html = file.readString(); + server.send(200, "text/html", html); + file.close(); + return; + } + } + server.send(404, "text/plain", "Page not found"); +} \ No newline at end of file diff --git a/src/WebServer.h b/src/WebServer.h new file mode 100644 index 0000000..0383eeb --- /dev/null +++ b/src/WebServer.h @@ -0,0 +1,3 @@ +extern ESP8266WebServer server; + +void handlePage(char *page); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fc2537e..3063b2c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,58 +24,6 @@ Adafruit_SSD1306 *display; // Create web server instance on port 80 ESP8266WebServer server(80); -// // HTML content for welcome page -// const char* welcome_html = R"HTML( -// -// -// -// -// -// Welcome to ESP8266 DCC Command Station -// -// -// -//
-//

Welcome!

-//

This is your ESP8266 DCC Command Station.

-//

Configure WiFi, manage XpressNet, and control your layout from here.

-//

For documentation, see XpressNet Commands and Hardware Setup.

-//
-// -// -// )HTML"; - -void handleWelcome() { - 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() { Serial.begin(115200); delay(100); @@ -96,19 +44,12 @@ void setup() { } } 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.on("/", []() { handlePage("/index.html"); }); + server.on("/xpressnet.html", []() { handlePage("/xpressnet.html"); }); + server.on("/mouse.html", []() { handlePage("/mouse.html"); }); + server.on("/js/script.js", []() { handlePage("/js/script.js"); }); + server.on("/css/style.css", []() { handlePage("/css/style.css"); }); server.begin(); Serial.println("[DEBUG] Web server started"); }