Add NFC access control support to Olimex ESP32-C6-EVB driver

- Add get_nfc_status() to retrieve NFC reader state (last UID, access state, auth config)
- Add set_nfc_config() to push NFC access-control config (auth_uid, relay_num, pulse_ms)
- Update API endpoint documentation in module docstring
This commit is contained in:
2026-03-15 08:46:35 +02:00
parent b4db41a400
commit 4766faa682

View File

@@ -14,6 +14,12 @@ POST /relay/toggle?relay=<n> → {"state": <new>}
GET /relay/status?relay=<n> → {"state": <bool>}
GET /input/status?input=<n> → {"state": <bool>}
POST /register?callback_url=<url> → {"status": "ok"}
GET /nfc/status → {"initialized": bool, "card_present": bool,
"last_uid": str, "access_state": str,
"auth_uid": str, "relay_num": int,
"pulse_ms": int}
GET /nfc/config → {"auth_uid": str, "relay_num": int, "pulse_ms": int}
POST /nfc/config?auth_uid=&relay=&pulse_ms= → {"status": "ok", ...}
Webhook (board → server)
------------------------
@@ -129,7 +135,44 @@ class OlimexESP32C6EVBDriver(BoardDriver):
url = f"{board.base_url}/register?callback_url={callback_url}"
ok = _post(url) is not None
if ok:
logger.info("Webhook registered on board '%s' %s", board.name, callback_url)
logger.info("Webhook registered on board '%s' \u2192 %s", board.name, callback_url)
else:
logger.warning("Webhook registration failed for board '%s'", board.name)
return ok
# ── NFC access control ──────────────────────────────────────────────────────
def get_nfc_status(self, board: "Board") -> dict | None:
"""Return current NFC reader status (last UID, access_state, auth config)."""
return _get(f"{board.base_url}/nfc/status")
def set_nfc_config(
self,
board: "Board",
auth_uid: str = "",
relay_num: int = 1,
pulse_ms: int = 3000,
) -> bool:
"""Push NFC access-control config to the board.
auth_uid: authorized card UID (e.g. "04:AB:CD:EF"); empty = any card opens relay.
relay_num: which relay to open on a matching card (1-4).
pulse_ms: how long to hold the relay open in milliseconds (100-60000).
"""
import urllib.parse
url = (
f"{board.base_url}/nfc/config"
f"?auth_uid={urllib.parse.quote(auth_uid.upper())}"
f"&relay={relay_num}"
f"&pulse_ms={pulse_ms}"
)
result = _post(url)
if result:
logger.info(
"NFC config pushed to board '%s': uid='%s' relay=%d pulse=%dms",
board.name, auth_uid, relay_num, pulse_ms,
)
else:
logger.warning("NFC config push failed for board '%s'", board.name)
return result is not None