From f9dc8b0d57b3f6cd4300e06c78768f3c7bc6a409 Mon Sep 17 00:00:00 2001 From: wwartana Date: Sat, 13 Dec 2025 21:08:31 +0800 Subject: [PATCH] Berhasil & Stabil --- src/main.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2e6e286..05946bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -264,7 +265,19 @@ void broadcastStatus() { // Web server endpoints ////////////////////////////////////////////////////////////////////////// void initWebServer() { + // Serve static files from LittleFS server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html"); + + // Add a catch-all handler for 404 errors to prevent file system errors + server.onNotFound([](AsyncWebServerRequest *request){ + // Check if it's an API request that doesn't exist + if (request->url().startsWith("/api/")) { + request->send(404, "text/plain", "API endpoint not found"); + } else { + // For non-API requests, try to serve the file + request->send(LittleFS, request->url(), "text/html"); + } + }); // settings page (no longer protected - has login form) server.on("/setting.html", HTTP_GET, [](AsyncWebServerRequest *req){ @@ -488,6 +501,10 @@ void resetAdminToDefault() { // Setup & Loop ////////////////////////////////////////////////////////////////////////// void setup(){ + // Initialize Task Watchdog Timer (TWDT) to prevent watchdog resets + esp_task_wdt_init(30, true); // 30 seconds timeout, panic on timeout + esp_task_wdt_add(NULL); // Add current task to watchdog + pinMode(STATUS_LED_PIN, OUTPUT); digitalWrite(STATUS_LED_PIN, LOW); pinMode(RELAY_PIN, OUTPUT); @@ -682,5 +699,8 @@ void loop(){ digitalWrite(BUZZER_PIN, LOW); } + // Reset Task Watchdog Timer to prevent timeout + esp_task_wdt_reset(); + delay(10); // tiny yield }