diff --git a/esp32_arduino/esp32_arduino.ino b/esp32_arduino/esp32_arduino.ino index bd65304..518b0db 100644 --- a/esp32_arduino/esp32_arduino.ino +++ b/esp32_arduino/esp32_arduino.ino @@ -8,7 +8,7 @@ * * Provides REST API for Home Assistant integration */ -// version 1.8 Initial release +// version 1.9 Initial release #include #include #include @@ -24,6 +24,13 @@ #define NFC_RX_PIN 5 // UEXT1 pin 4 — ESP32 receives from PN532 #define NFC_POLL_MS 500 // idle detection interval (ms) +// ── Web UI credentials ──────────────────────────────────────────────────── +// Only browser-facing pages (/ and /debug) are protected. +// All REST API endpoints are intentionally left open so the Location +// Management board driver can communicate without credentials. +#define WEB_USER "ske087" +#define WEB_PASSWORD "Matei@123" + HardwareSerial nfcSerial(1); // UART1 PN532_HSU pn532hsu(nfcSerial); PN532 nfc(pn532hsu); @@ -398,6 +405,8 @@ void scanWiFiNetworks() { // ============================================ void handleRoot() { + if (!requireAuth()) return; + // Read all inputs first to get current state input1_state = digitalRead(DIN1_PIN); input2_state = digitalRead(DIN2_PIN); @@ -635,6 +644,16 @@ void handleRoot() { server.send(200, "text/html", html); } +// ── Web UI authentication helper ──────────────────────────────────────── +bool requireAuth() { + if (!server.authenticate(WEB_USER, WEB_PASSWORD)) { + server.requestAuthentication(DIGEST_AUTH, "ESP32-C6 Control Panel", + "Login required"); + return false; + } + return true; +} + // Status request monitoring static unsigned long last_status_log = 0; static int status_request_count = 0; @@ -1016,6 +1035,8 @@ void handleNFCConfigSet() { // ============================================ void handleDebug() { + if (!requireAuth()) return; + String out = "=== ESP32-C6 Debug ===\n"; out += "Uptime: " + String(millis() / 1000) + " s\n"; out += "Free heap: " + String(ESP.getFreeHeap()) + " bytes\n";