@@ -253,6 +253,10 @@ void rfidRead()
253
253
}
254
254
}
255
255
256
+
257
+ /*
258
+ * Try and read a PIN code from Wiegand hardware
259
+ */
256
260
void pinCodeRead()
257
261
{
258
262
if (config.readertype != READER_WIEGAND ||
@@ -320,6 +324,11 @@ int weekdayFromMonday(int weekdayFromSunday) {
320
324
return ( weekdayFromSunday + 5 ) % 7;
321
325
}
322
326
327
+
328
+ /*
329
+ * If we have successfully read an RFID card, check if access
330
+ * should be granted
331
+ */
323
332
void rfidProcess()
324
333
{
325
334
if (rfidState == waitingRfid ||
@@ -328,12 +337,14 @@ void rfidProcess()
328
337
return;
329
338
}
330
339
340
+ /* Each user has a file named after the RFID UID */
331
341
File f = SPIFFS.open("/P/" + uid, "r");
332
342
333
343
/*
334
344
* If the file was not found then this is an unknown user, so no more
335
- * processing to be done. However, we do a secondary check here to see
336
- * if an old esp-rfid v1 uid exists and if so use that.
345
+ * processing to be done. However, for backwards compatibility we do a
346
+ * secondary check here to see if an old esp-rfid v1 uid exists and if
347
+ * so use that.
337
348
*/
338
349
if (!f)
339
350
{
@@ -352,13 +363,19 @@ void rfidProcess()
352
363
#endif
353
364
}
354
365
366
+ /*
367
+ * Read the user's settings
368
+ */
355
369
size_t size = f.size();
356
370
std::unique_ptr<char[]> buf(new char[size]);
357
371
f.readBytes(buf.get(), size);
358
372
f.close();
359
373
DynamicJsonDocument json(512);
360
374
auto error = deserializeJson(json, buf.get(), size);
361
375
376
+ /*
377
+ * Corrupt user data file, so return invalid user
378
+ */
362
379
if (error)
363
380
{
364
381
processingState = notValid;
@@ -380,24 +397,32 @@ void rfidProcess()
380
397
return;
381
398
}
382
399
400
+ /*
401
+ * Get account type (for FIRST relay only) and username from user's data
402
+ */
383
403
accountType = json["acctype"];
384
404
username = json["user"].as<String>();
385
405
386
406
#ifdef DEBUG
387
407
Serial.println(" = known PICC");
388
- Serial.print("[ INFO ] User Name: ");
408
+ Serial.print("[ INFO ] User Name: ' ");
389
409
if (username == "undefined")
390
410
Serial.print(uid);
391
411
else
392
412
Serial.print(username);
413
+ Serial.print("'");
393
414
#endif
394
415
395
416
if (accountType == ACCESS_GRANTED)
396
417
{
418
+ /*
419
+ * Normal user - relay but no admin access
420
+ */
397
421
unsigned long validSinceL = json["validsince"];
398
422
unsigned long validUntilL = json["validuntil"];
399
423
unsigned long nowL = epoch;
400
424
int hourTz = timeinfo.tm_hour;
425
+
401
426
if (validUntilL < nowL || validSinceL > nowL)
402
427
{
403
428
processingState = expired;
@@ -410,9 +435,15 @@ void rfidProcess()
410
435
}
411
436
} else if (accountType == ACCESS_ADMIN)
412
437
{
438
+ /*
439
+ * Admin user - enable relay (with no time limits) and wifi
440
+ */
413
441
doEnableWifi = true;
414
442
processingState = validAdmin;
415
443
} else {
444
+ /*
445
+ * User exists but does not have access
446
+ */
416
447
processingState = notValid;
417
448
}
418
449
0 commit comments