This commit is contained in:
2026-03-15 09:42:26 +02:00
parent 22227b7e21
commit 0f7cfdb819

View File

@@ -8,7 +8,7 @@
*
* Provides REST API for Home Assistant integration
*/
// version 1.8 Initial release
// version 1.9 Initial release
#include <WiFi.h>
#include <WebServer.h>
#include <WiFiClient.h>
@@ -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";