ESP RFID Webui
Architecture and call graph
Loading...
Searching...
No Matches
main.cpp File Reference
#include <freertos/queue.h>
#include "TimerHandle.h"
#include "AuthSync.h"
#include "ConfigManager.h"
#include "HardwareSerial.h"
#include "HashUtils.h"
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <LittleFS.h>
#include <MFRC522.h>
#include <SPI.h>
#include <U8x8lib.h>
#include <WiFi.h>
#include <Wire.h>
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

struct  ScanItem

Functions

MFRC522 rfid (SS_PIN, RST_PIN)
U8X8_SSD1315_128X64_NONAME_SW_I2C u8x8 (22, 21, U8X8_PIN_NONE)
String getUidString ()
void updateEnrollStatus ()
void updateDisplay ()
void drawHeader ()
void drawEnrollIndicator (bool on)
void NetworkTask (void *pv)
bool postLastScan (const String &uid, JsonDocument &out)
static void displayTimerCallback (TimerHandle_t xTimer)
void setup ()
void loop ()
void serverCheckTimerCallback (TimerHandle_t xTimer)
void authSyncTimerCallback (TimerHandle_t xTimer)

Variables

constexpr uint8_t RST_PIN = 17
constexpr uint8_t SS_PIN = 5
static constexpr unsigned long ENROLL_POLL_INTERVAL_MS = 5000
String SSID = ""
String PASS = ""
String SERVER_BASE = ""
AuthSyncauthSync = nullptr
String lastUID = "NONE"
String enrollMode = "none"
bool lastAuthorized = false
uint64_t lastHash = 0
bool serverReachable = false
unsigned long lastDisplayUpdate = 0
unsigned long enrollBlinkMillis = 0
bool enrollBlinkState = false
static unsigned long lastEnrollPoll = 0
String displayedUID = ""
bool displayedAuth = false
uint64_t displayedHash = 0
String displayedEnrollMode = ""
bool displayedEnrollBlink = false
bool displayedServerReachable = false
static QueueHandle_t scanQueue = nullptr
static volatile bool authSyncRequested = false
static volatile bool displayUpdateRequested = false

Function Documentation

◆ authSyncTimerCallback()

void authSyncTimerCallback ( TimerHandle_t xTimer)

Definition at line 572 of file main.cpp.

573{
574 authSyncRequested = true;
575}
static volatile bool authSyncRequested
Definition main.cpp:123

References authSyncRequested.

Referenced by NetworkTask().

Here is the caller graph for this function:

◆ displayTimerCallback()

void displayTimerCallback ( TimerHandle_t xTimer)
static

Definition at line 126 of file main.cpp.

126{ (void)xTimer; displayUpdateRequested = true; }
static volatile bool displayUpdateRequested
Definition main.cpp:125

References displayUpdateRequested.

Referenced by setup().

Here is the caller graph for this function:

◆ drawEnrollIndicator()

void drawEnrollIndicator ( bool on)

Definition at line 450 of file main.cpp.

451{
452 String currentMode = enrollMode;
453 bool currentBlink = on;
454
455 // Only redraw if mode or blink state changed - Full redraws are visible
456 if (currentMode != displayedEnrollMode ||
457 currentBlink != displayedEnrollBlink) {
458 if (enrollMode == "none") {
459 u8x8.drawString(14, 0, " ");
460 } else if (on) {
461 u8x8.drawString(14, 0, enrollMode == "grant" ? "GR" : "RV");
462 } else {
463 u8x8.drawString(14, 0, " ");
464 }
465 displayedEnrollMode = currentMode;
466 displayedEnrollBlink = currentBlink;
467 }
468}
bool displayedEnrollBlink
Definition main.cpp:104
String displayedEnrollMode
Definition main.cpp:103
U8X8_SSD1315_128X64_NONAME_SW_I2C u8x8(22, 21, U8X8_PIN_NONE)
String enrollMode
Definition main.cpp:88

References displayedEnrollBlink, displayedEnrollMode, enrollMode, and u8x8().

Referenced by loop(), and updateDisplay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawHeader()

void drawHeader ( )

Definition at line 392 of file main.cpp.

393{
394 static bool headerDrawn = false;
395 if (!headerDrawn) {
396 u8x8.clear();
397 u8x8.drawString(0, 0, "RFID Access");
398 headerDrawn = true;
399 }
400}

References u8x8().

Referenced by setup(), and updateDisplay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUidString()

String getUidString ( )

Definition at line 380 of file main.cpp.

381{
382 String uid = "";
383 for (byte i = 0; i < rfid.uid.size; i++) {
384 if (rfid.uid.uidByte[i] < 0x10)
385 uid += "0";
386 uid += String(rfid.uid.uidByte[i], HEX);
387 }
388 uid.toUpperCase();
389 return uid;
390}
MFRC522 rfid(SS_PIN, RST_PIN)

References rfid().

Referenced by loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loop()

void loop ( )

Definition at line 305 of file main.cpp.

305 {
306 // Server reachability check now handled by FreeRTOS timer in NetworkTask
307
308 if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
309 String uid = getUidString();
310 Serial.println("Scanned: " + uid);
311 lastUID = uid;
312
313 // Compute hash for display (same method as AuthSync) ----------- FOR
314 // DEBUGGING ----
315 /*String normalized = uid;
316 normalized.trim();
317 normalized.toUpperCase();
318 uint64_t hash = 0xcbf29ce484222325ULL;
319 for (size_t i = 0; i < normalized.length(); i++) {
320 constexpr uint64_t prime = 0x100000001b3ULL;
321 hash ^= static_cast<uint8_t>(normalized[i]);
322 hash *= prime;
323 }*/
324
326 lastAuthorized = authSync ? authSync->isAuthorized(uid) : false;
327 updateEnrollStatus(); // Refresh after scan
329 rfid.PICC_HaltA();
330 rfid.PCD_StopCrypto1();
331 vTaskDelay(100 / portTICK_PERIOD_MS); // Debounce recommended delay
332 // Defer network POST of last scan to network task via queue
333 if (scanQueue) {
334 ScanItem item{};
335 uid.toCharArray(item.uid, sizeof(item.uid));
336 if (xQueueSend(scanQueue, &item, 0) != pdPASS) {
337 Serial.println("[Queue] scanQueue full; dropping UID post");
338 } else {
339 Serial.printf("[Queue] Enqueued UID=%s\n", item.uid);
340 }
341 }
342 }
343
344 // Periodic sync handled by NetworkTask
345
346 // Display updates are requested by a timer; perform the actual update in
347 // loop() context to keep display code single-threaded and safe for the
348 // U8x8 library.
352 lastDisplayUpdate = millis();
353 }
354
355 // Blink indicator when waiting for enroll
356 if (enrollMode != "none" && millis() - enrollBlinkMillis > 500) {
358 enrollBlinkMillis = millis();
360 }
361
362 // Simple millis-based enroll-mode poll
363 if (millis() - lastEnrollPoll > ENROLL_POLL_INTERVAL_MS) {
364 lastEnrollPoll = millis();
366 }
367
368#ifdef AUTH_TEST_HOOK
369 // Test hook: press 'm' on serial to print memory stats
370 if (Serial.available()) {
371 int c = Serial.read();
372 if (c == 'm' || c == 'M') {
373 if (authSync) authSync->TEST_dumpMemoryStats();
374 }
375 }
376#endif
377}
AuthSync * authSync
Definition main.cpp:84
unsigned long lastDisplayUpdate
Definition main.cpp:92
uint64_t lastHash
Definition main.cpp:90
bool enrollBlinkState
Definition main.cpp:94
String lastUID
Definition main.cpp:87
bool lastAuthorized
Definition main.cpp:89
void drawEnrollIndicator(bool on)
Definition main.cpp:450
static constexpr unsigned long ENROLL_POLL_INTERVAL_MS
Definition main.cpp:61
void updateEnrollStatus()
Definition main.cpp:512
String getUidString()
Definition main.cpp:380
static unsigned long lastEnrollPoll
Definition main.cpp:97
void updateDisplay()
Definition main.cpp:402
unsigned long enrollBlinkMillis
Definition main.cpp:93
static QueueHandle_t scanQueue
Definition main.cpp:119
uint64_t hashUid(const String &s)
Definition HashUtils.cpp:18
char uid[21]
Definition main.cpp:117

References authSync, displayUpdateRequested, drawEnrollIndicator(), ENROLL_POLL_INTERVAL_MS, enrollBlinkMillis, enrollBlinkState, enrollMode, getUidString(), HashUtils::hashUid(), AuthSync::isAuthorized(), lastAuthorized, lastDisplayUpdate, lastEnrollPoll, lastHash, lastUID, rfid(), scanQueue, ScanItem::uid, updateDisplay(), and updateEnrollStatus().

Here is the call graph for this function:

◆ NetworkTask()

void NetworkTask ( void * pv)

Definition at line 578 of file main.cpp.

579{
580 Serial.printf("[Tasks] NetworkTask running on core %d\n", xPortGetCoreID());
581
582
583 // Create and start the timer (5000ms period, auto-reload)
584 if (!createServerCheckTimer(serverCheckTimerCallback, pdMS_TO_TICKS(5000))) {
585 Serial.println("[Tasks] Failed to create/start server check timer");
586 } else {
587 Serial.println("[Tasks] Server check timer started");
588 }
589
590 // Create and start the auth sync timer (non-blocking callback)
591 if (!createAuthSyncTimer(authSyncTimerCallback, pdMS_TO_TICKS(5000))) {
592 Serial.println("[Tasks] Failed to create/start auth sync timer");
593 } else {
594 Serial.println("[Tasks] AuthSync timer started");
595 }
596
597 for (;;) {
598 // AuthSync periodic sync — triggered by timer flag (non-blocking timer
599 // callback)
601 authSyncRequested = false; // clear flag before doing work
602 authSync->update();
603 Serial.println("[Tasks] Auth sync requested");
604 }
605
606 // Drain scan queue: post last_scan events (limit per cycle)
607 if (serverReachable && scanQueue) {
608 for (int i = 0; i < 3;
609 ++i) {
610 // process up to 3 per loop to avoid starving
611 ScanItem item;
612 if (xQueueReceive(scanQueue, &item, 0) == pdPASS) {
613 // Post scan to server and handle enrollment side-effects returned by
614 // the server.
615 Serial.printf("[Queue] Posting UID=%s\n", item.uid);
616 JsonDocument resp;
617
618 if (postLastScan(String(item.uid), resp)) {
619 Serial.printf("[Queue] postLastScan returned size=%u\n", static_cast<unsigned>(resp.size()));
620 // If server acknowledged enrollment, clear enroll mode and redraw
621 // indicator immediately
622 if (resp.size() > 0) {
623 bool enrolled = false;
624 if (resp["enrolled"].is<bool>()) {
625 enrolled = resp["enrolled"].as<bool>();
626 }
627 if (enrolled) {
628 enrollMode = "none";
629 // Request main loop to redraw the enroll indicator (display
630 // operations must run from loop context to be thread-safe).
632 Serial.println("[Queue] Enrollment cleared (requested display update)");
633 }
634 }
635 } else {
636 Serial.println("[Queue] postLastScan: no valid response");
637 }
638 } else {
639 break;
640 }
641 }
642 } else if (!serverReachable && scanQueue) {
643 // When offline, keep queued scans for later (do not drop them).
644 // Optionally we could limit queue size elsewhere, but avoid clearing here.
645 }
646
647 vTaskDelay(pdMS_TO_TICKS(50));
648 }
649}
bool createServerCheckTimer(TimerCallbackFunction_t callback, TickType_t periodTicks)
bool createAuthSyncTimer(TimerCallbackFunction_t callback, TickType_t periodTicks)
bool postLastScan(const String &uid, JsonDocument &out)
Definition main.cpp:470
void authSyncTimerCallback(TimerHandle_t xTimer)
Definition main.cpp:572
void serverCheckTimerCallback(TimerHandle_t xTimer)
Definition main.cpp:548
bool serverReachable
Definition main.cpp:91

References authSync, authSyncRequested, authSyncTimerCallback(), createAuthSyncTimer(), createServerCheckTimer(), displayUpdateRequested, enrollMode, postLastScan(), scanQueue, serverCheckTimerCallback(), serverReachable, ScanItem::uid, and AuthSync::update().

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postLastScan()

bool postLastScan ( const String & uid,
JsonDocument & out )

Definition at line 470 of file main.cpp.

471{
472 out.clear();
473 // Guard: if we're offline or server not configured, return empty doc.
474 // This avoids making invalid HTTP calls when no server_base is provided
475 // (e.g. on first-boot before provisioning /config.json).
476 if (WiFi.status() != WL_CONNECTED)
477 return false;
478 if (SERVER_BASE.length() == 0)
479 return false;
480 // Escape: if we already marked serverReachable false, skip HTTP entirely
481 if (!serverReachable) {
482 // Uncomment for verbose logging: Serial.println("[postLastScan] Skipped
483 // (serverReachable=false)");
484 return false;
485 }
486 HTTPClient http;
487 http.setTimeout(1500); // shorter timeout to avoid long blocking
488 http.begin(String(SERVER_BASE) + "/api/last_scan");
489 http.addHeader("Content-Type", "application/json");
490 String body = R"({"uid":")" + uid + "\"}";
491 int code = http.POST(body);
492 Serial.printf("[HTTP] POST /api/last_scan -> code=%d, body=%s\n", code, body.c_str());
493 if (code < 200 || code >= 300) {
494 Serial.printf("postLastScan failed: %d\n", code);
495 http.end();
496 return false;
497 }
498 String payload = http.getString();
499 Serial.printf("[HTTP] /api/last_scan payload: %s\n", payload.c_str());
500 http.end();
501 // Parse into caller-provided document (prefer StaticJsonDocument in caller)
502 DeserializationError err = deserializeJson(out, payload);
503 if (err) {
504 Serial.printf("postLastScan: JSON parse error: %s\n", err.c_str());
505 out.clear();
506 return false;
507 }
508 return true;
509}
String SERVER_BASE
Definition main.cpp:80

References SERVER_BASE, and serverReachable.

Referenced by NetworkTask().

Here is the caller graph for this function:

◆ rfid()

MFRC522 rfid ( SS_PIN ,
RST_PIN  )

Referenced by getUidString(), loop(), and setup().

Here is the caller graph for this function:

◆ serverCheckTimerCallback()

void serverCheckTimerCallback ( TimerHandle_t xTimer)

Definition at line 548 of file main.cpp.

549{
550 bool nowReachable = false;
551 if (WiFiClass::status() == WL_CONNECTED && SERVER_BASE.length() > 0) {
552 HTTPClient http;
553 http.setTimeout(1500);
554 http.begin(SERVER_BASE + "/api/status");
555 int code = http.GET();
556 http.end();
557 nowReachable = (code == 200);
558 }
559 if (nowReachable != serverReachable) {
560 serverReachable = nowReachable;
561 Serial.printf("[DB] Reachable=%d\n", serverReachable);
562 // Keep AuthSync's cached probe state in sync with the central timer so
563 // both modules make decisions from the same reachability information.
564 if (authSync) {
565 authSync->setServerProbeResult(nowReachable, millis());
566 }
567 }
568}

References authSync, SERVER_BASE, serverReachable, and AuthSync::setServerProbeResult().

Referenced by NetworkTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup()

void setup ( )

Definition at line 129 of file main.cpp.

129 {
130 Serial.begin(115200);
131 vTaskDelay(500 / portTICK_PERIOD_MS);
132 Serial.println(" hello world!");
133
134 // Force first auth line to render even if initial authorization is false
135 // by priming displayedAuth opposite of lastAuthorized.
137
138 Wire.begin(21, 22);
139 u8x8.begin();
140 u8x8.setFont(u8x8_font_chroma48medium8_r);
141 drawHeader();
142 u8x8.drawString(0, 2, "FS Init...");
143
144 SPI.begin();
145 rfid.PCD_Init();
146
147 // Ensure FS is mounted before trying to load config
148 if (LittleFS.begin()) {
150 Serial.println("Config loaded from LittleFS");
151 Serial.println("SSID: " + SSID);
152 Serial.println("PASS: " + PASS);
153 Serial.println("SERVER_BASE: " + SERVER_BASE);
154 u8x8.drawString(0, 2, "FS OK ");
155 // Create AuthSync early so we can load offline caches from NVS
156 if (SERVER_BASE.length() > 0) {
158 // AuthSync constructed — delay offline preload until after WiFi
159 // initialization so any network-related state is stable.
160 } else {
161 Serial.println("SERVER_BASE empty; offline authorization disabled "
162 "until configured");
163 }
164 } /* ------------- If failing to flash config.json, run auto-provisioning
165 ------------- Replace this placeholder with your desired network
166 details to have the device write config.json on first boot.
167 ------------- ------------- ------------- ------------- -------------
168 -------------*/
169 /*else {
170 Serial.println("config.json missing -> auto-provisioning defaults");
171 // One-time provisioning: write a default config, then reload.
172 if (ConfigManager::saveConfig("SSID", "PASSWORD",
173 "http://SERVER_Base")) { if (ConfigManager::loadConfig(SSID, PASS,
174 SERVER_BASE)) { Serial.println("Provisioned default config.json");
175 Serial.println("SSID: " + SSID);
176 Serial.println("PASS: " + PASS);
177 Serial.println("SERVER_BASE: " + SERVER_BASE);
178 u8x8.drawString(0, 2, "PROVISION");
179 } else {
180 Serial.println("Provision write ok but reload failed");
181 u8x8.drawString(0, 2, "PROV ERR");
182 }
183 } else {
184 Serial.println("Failed to auto-provision config.json");
185 u8x8.drawString(0, 2, "PROV FAIL");
186 }
187 }
188 ConfigManager::listFiles();
189 } else {
190 Serial.println("LittleFS mount failed, formatting...");
191 LittleFS.format();
192 if (LittleFS.begin()) {
193 Serial.println("LittleFS formatted and remounted");
194 if (ConfigManager::loadConfig(SSID, PASS, SERVER_BASE)) {
195 Serial.println("Config loaded from LittleFS");
196 ConfigManager::listFiles();
197 }
198 } else {
199 Serial.println("LittleFS format/remount failed");
200 u8x8.drawString(0, 2, "FS FAIL");
201 }*/
202 }
203 vTaskDelay(100 /
204 portTICK_PERIOD_MS); // Give some time for LittleFS to stabilize
205
206 WiFi.begin(SSID.c_str(), PASS.c_str());
207 // After Wi-Fi initialization, perform the offline preload (loads NVS + FS
208 // caches) so AuthSync can have its cached data ready before any network
209 // sync attempts. Doing this after WiFi.begin keeps the ordering stable.
210 if (authSync) {
211 authSync->preloadOffline();
212 authSync->dumpMemoryStats();
213 Serial.println("[AuthSync] Offline cache preloaded (after WiFi init)");
214 }
215 int tries = 0;
216 while (WiFiClass::status() != WL_CONNECTED && tries < 80) {
217 vTaskDelay(500 / portTICK_PERIOD_MS);
218 Serial.print(".");
219 tries++;
220 }
221
222 if (WiFiClass::status() == WL_CONNECTED) {
223 Serial.println("");
224 Serial.println("WiFi connected");
225 Serial.print("IP address: ");
226 Serial.println(WiFi.localIP());
227 u8x8.drawString(0, 2, "WiFi OK ");
228 // Wifi modem sleep
229 WiFi.setSleep(true);
230 vTaskDelay(100 / portTICK_PERIOD_MS);
231
232 // Attempt an online sync now that WiFi is connected (we already loaded
233 // offline cache)
234 bool syncOk = false;
235 if (authSync) {
236 // Use public begin() to perform an immediate sync (reloads NVS + attempts
237 // server sync)
238 syncOk = authSync->begin();
239 }
240 if (syncOk) {
241 u8x8.drawString(0, 3, "DB OK");
242 serverReachable = true;
244 } else {
245 u8x8.drawString(0, 3, "DB OFFLINE ");
246 serverReachable = false;
248 Serial.println(
249 "[AuthSync] Using offline cache (sync failed or server unreachable)");
250 }
251 } else {
252 u8x8.drawString(0, 2, "WiFi FAIL");
253 serverReachable = false;
255 }
256 vTaskDelay(100 / portTICK_PERIOD_MS);
257
258 // Create queue and network task (pin to core 0, lower priority than loop for
259 // RFID responsiveness)
260 //Note: this was implemented in a phase where there was no NetworkTask yet
261 // Could probably just be lower priority
262 if (!scanQueue) {
263 scanQueue = xQueueCreate(10, sizeof(ScanItem));
264
265
266 //Configure UNICORE flag in platformio.ini if using a single-core ESP32
267#if defined(CONFIG_FREERTOS_UNICORE)
268
269 xTaskCreate(
271 "net_task",
272 4096,
273 nullptr,
274 tskIDLE_PRIORITY,
275 nullptr);
276
277 Serial.println("[Tasks] NetworkTask started on IdleTask priority");
278#else
279 xTaskCreatePinnedToCore(
281 "net_task",
282 4096,
283 nullptr,
284 tskIDLE_PRIORITY,
285 nullptr,
286 0);
287 Serial.println("[Tasks] NetworkTask started on IdleTask priority");
288#endif
289 // Runtime fallback: query chip info (works on Arduino and esp-idf)
290 if (scanQueue) {
291 Serial.println("[Tasks] scanQueue created");
292 } else {
293 Serial.println("[Tasks] Failed to create scanQueue");
294 }
295 }
296 // Create timers using centralized helpers (TimerHandle.cpp)
297 if (!createDisplayTimer(displayTimerCallback, pdMS_TO_TICKS(500))) {
298 Serial.println("[Tasks] Failed to create/start display timer");
299 } else {
300 Serial.println("[Tasks] Display timer started");
301 }
302
303}
bool createDisplayTimer(TimerCallbackFunction_t callback, TickType_t periodTicks)
static bool loadConfig(String &ssid, String &pass, String &serverBase)
bool displayedAuth
Definition main.cpp:101
void NetworkTask(void *pv)
Definition main.cpp:578
String PASS
Definition main.cpp:79
String SSID
Definition main.cpp:78
bool displayedServerReachable
Definition main.cpp:105
static void displayTimerCallback(TimerHandle_t xTimer)
Definition main.cpp:126
void drawHeader()
Definition main.cpp:392

References AuthSync::AuthSync(), authSync, AuthSync::begin(), createDisplayTimer(), displayedAuth, displayedServerReachable, displayTimerCallback(), drawHeader(), AuthSync::dumpMemoryStats(), lastAuthorized, ConfigManager::loadConfig(), NetworkTask(), PASS, AuthSync::preloadOffline(), rfid(), scanQueue, SERVER_BASE, serverReachable, SSID, and u8x8().

Here is the call graph for this function:

◆ u8x8()

U8X8_SSD1315_128X64_NONAME_SW_I2C u8x8 ( 22 ,
21 ,
U8X8_PIN_NONE  )

Referenced by drawEnrollIndicator(), drawHeader(), setup(), and updateDisplay().

Here is the caller graph for this function:

◆ updateDisplay()

void updateDisplay ( )

Definition at line 402 of file main.cpp.

403{
404 drawHeader(); // Only draws once
405
406 // Update DB status if changed
408 if (serverReachable) {
409 u8x8.drawString(0, 3, "DB OK ");
410 } else {
411 u8x8.drawString(0, 3, "DB LOST ");
412 }
414 }
415
416 // Only update UID if changed
417 if (lastUID != displayedUID) {
418 String line = "UID:" + lastUID;
419 if (line.length() > 16)
420 line = line.substring(0, 16);
421 // Pad with spaces to clear old text
422 while (line.length() < 16)
423 line += " ";
424 u8x8.drawString(0, 1, line.c_str());
426 }
427
428 // Only update auth status if changed
430 u8x8.drawString(
431 0, 4, (String("Auth:") + (lastAuthorized ? "YES" : "NO ")).c_str());
433 }
434
435 // Update hash display (last 8 hex digits on bottom row)
436 if (lastHash != displayedHash) {
437 char hashStr[17];
438 snprintf(hashStr, sizeof(hashStr), "H:%08X",
439 static_cast<uint32_t>(lastHash & 0xFFFFFFFF));
440 u8x8.drawString(0, 7, hashStr);
442 }
443
444 // Update enroll indicator if mode changed
447 }
448}
uint64_t displayedHash
Definition main.cpp:102
String displayedUID
Definition main.cpp:100

References displayedAuth, displayedEnrollMode, displayedHash, displayedServerReachable, displayedUID, drawEnrollIndicator(), drawHeader(), enrollMode, lastAuthorized, lastHash, lastUID, serverReachable, and u8x8().

Referenced by loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateEnrollStatus()

void updateEnrollStatus ( )

Definition at line 512 of file main.cpp.

513{
514 // Skip poll if offline or no server configured. Keeps display consistent
515 // and avoids pointless HTTP requests when not provisioned.
516 if (WiFi.status() != WL_CONNECTED || SERVER_BASE.length() == 0) {
517 enrollMode = "none";
518 serverReachable = false;
519 return;
520 }
521 // Simple synchronous status poll (called from loop() on a millis timer)
522 HTTPClient http;
523 http.setTimeout(1500);
524 String url = SERVER_BASE + "/api/status";
525 http.begin(url);
526 int code = http.GET();
527 if (code > 0 && code < 400)
528 serverReachable = true;
529 String payload = http.getString();
530 JsonDocument doc;
531 DeserializationError err = deserializeJson(doc, payload);
532 if (!err) {
533 const char *m = doc["enroll_mode"] | nullptr;
534
535 if (m && strlen(m) > 0) {
536 enrollMode = m;
537 } else {
538 enrollMode = "none";
539 }
540 } else {
541 serverReachable = false;
542 enrollMode = "none";
543 }
544 http.end();
545}

References enrollMode, SERVER_BASE, and serverReachable.

Referenced by loop().

Here is the caller graph for this function:

Variable Documentation

◆ authSync

AuthSync* authSync = nullptr

Definition at line 84 of file main.cpp.

Referenced by loop(), NetworkTask(), serverCheckTimerCallback(), and setup().

◆ authSyncRequested

volatile bool authSyncRequested = false
static

Definition at line 123 of file main.cpp.

Referenced by authSyncTimerCallback(), and NetworkTask().

◆ displayedAuth

bool displayedAuth = false

Definition at line 101 of file main.cpp.

Referenced by setup(), and updateDisplay().

◆ displayedEnrollBlink

bool displayedEnrollBlink = false

Definition at line 104 of file main.cpp.

Referenced by drawEnrollIndicator().

◆ displayedEnrollMode

String displayedEnrollMode = ""

Definition at line 103 of file main.cpp.

Referenced by drawEnrollIndicator(), and updateDisplay().

◆ displayedHash

uint64_t displayedHash = 0

Definition at line 102 of file main.cpp.

Referenced by updateDisplay().

◆ displayedServerReachable

bool displayedServerReachable = false

Definition at line 105 of file main.cpp.

Referenced by setup(), and updateDisplay().

◆ displayedUID

String displayedUID = ""

Definition at line 100 of file main.cpp.

Referenced by updateDisplay().

◆ displayUpdateRequested

volatile bool displayUpdateRequested = false
static

Definition at line 125 of file main.cpp.

Referenced by displayTimerCallback(), loop(), and NetworkTask().

◆ ENROLL_POLL_INTERVAL_MS

unsigned long ENROLL_POLL_INTERVAL_MS = 5000
staticconstexpr

Definition at line 61 of file main.cpp.

Referenced by loop().

◆ enrollBlinkMillis

unsigned long enrollBlinkMillis = 0

Definition at line 93 of file main.cpp.

Referenced by loop().

◆ enrollBlinkState

bool enrollBlinkState = false

Definition at line 94 of file main.cpp.

Referenced by loop().

◆ enrollMode

String enrollMode = "none"

Definition at line 88 of file main.cpp.

Referenced by drawEnrollIndicator(), loop(), NetworkTask(), updateDisplay(), and updateEnrollStatus().

◆ lastAuthorized

bool lastAuthorized = false

Definition at line 89 of file main.cpp.

Referenced by loop(), setup(), and updateDisplay().

◆ lastDisplayUpdate

unsigned long lastDisplayUpdate = 0

Definition at line 92 of file main.cpp.

Referenced by loop().

◆ lastEnrollPoll

unsigned long lastEnrollPoll = 0
static

Definition at line 97 of file main.cpp.

Referenced by loop().

◆ lastHash

uint64_t lastHash = 0

Definition at line 90 of file main.cpp.

Referenced by loop(), and updateDisplay().

◆ lastUID

String lastUID = "NONE"

Definition at line 87 of file main.cpp.

Referenced by loop(), and updateDisplay().

◆ PASS

String PASS = ""

Definition at line 79 of file main.cpp.

Referenced by setup().

◆ RST_PIN

uint8_t RST_PIN = 17
constexpr

Definition at line 59 of file main.cpp.

◆ scanQueue

QueueHandle_t scanQueue = nullptr
static

Definition at line 119 of file main.cpp.

Referenced by loop(), NetworkTask(), and setup().

◆ SERVER_BASE

String SERVER_BASE = ""

Definition at line 80 of file main.cpp.

Referenced by postLastScan(), serverCheckTimerCallback(), setup(), and updateEnrollStatus().

◆ serverReachable

bool serverReachable = false

◆ SS_PIN

uint8_t SS_PIN = 5
constexpr

Definition at line 60 of file main.cpp.

◆ SSID

String SSID = ""

Definition at line 78 of file main.cpp.

Referenced by setup().