#include #include #include #include "DisplayHelper.h" #include "WiFiManagerHelper.h" #include "main.h" #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C // If not work please scan the bus #define OLED_SDA 14 // D6 #define OLED_SCL 12 // D5 // Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_SSD1306 *display; // Mode for command station operation // Remove conflicting definition, use extern from main.h // Mode currentMode = MODE_OFF; // 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); Serial.println("[DEBUG] Serial started at 115200 baud"); 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"); } void loop() { server.handleClient(); delay(1000); }