updated
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Provides REST API for Home Assistant integration
|
* Provides REST API for Home Assistant integration
|
||||||
*/
|
*/
|
||||||
// version 1.8 Initial release
|
// version 1.9 Initial release
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <WebServer.h>
|
#include <WebServer.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
@@ -24,6 +24,13 @@
|
|||||||
#define NFC_RX_PIN 5 // UEXT1 pin 4 — ESP32 receives from PN532
|
#define NFC_RX_PIN 5 // UEXT1 pin 4 — ESP32 receives from PN532
|
||||||
#define NFC_POLL_MS 500 // idle detection interval (ms)
|
#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
|
HardwareSerial nfcSerial(1); // UART1
|
||||||
PN532_HSU pn532hsu(nfcSerial);
|
PN532_HSU pn532hsu(nfcSerial);
|
||||||
PN532 nfc(pn532hsu);
|
PN532 nfc(pn532hsu);
|
||||||
@@ -398,6 +405,8 @@ void scanWiFiNetworks() {
|
|||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
void handleRoot() {
|
void handleRoot() {
|
||||||
|
if (!requireAuth()) return;
|
||||||
|
|
||||||
// Read all inputs first to get current state
|
// Read all inputs first to get current state
|
||||||
input1_state = digitalRead(DIN1_PIN);
|
input1_state = digitalRead(DIN1_PIN);
|
||||||
input2_state = digitalRead(DIN2_PIN);
|
input2_state = digitalRead(DIN2_PIN);
|
||||||
@@ -635,6 +644,16 @@ void handleRoot() {
|
|||||||
server.send(200, "text/html", html);
|
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
|
// Status request monitoring
|
||||||
static unsigned long last_status_log = 0;
|
static unsigned long last_status_log = 0;
|
||||||
static int status_request_count = 0;
|
static int status_request_count = 0;
|
||||||
@@ -1016,6 +1035,8 @@ void handleNFCConfigSet() {
|
|||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
void handleDebug() {
|
void handleDebug() {
|
||||||
|
if (!requireAuth()) return;
|
||||||
|
|
||||||
String out = "=== ESP32-C6 Debug ===\n";
|
String out = "=== ESP32-C6 Debug ===\n";
|
||||||
out += "Uptime: " + String(millis() / 1000) + " s\n";
|
out += "Uptime: " + String(millis() / 1000) + " s\n";
|
||||||
out += "Free heap: " + String(ESP.getFreeHeap()) + " bytes\n";
|
out += "Free heap: " + String(ESP.getFreeHeap()) + " bytes\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user