@@ -4,6 +4,7 @@ String currentInput = "";
4
4
String pinCode = "";
5
5
String type = "";
6
6
String uid = "";
7
+ String v1uid = "";
7
8
String username = "";
8
9
bool wiegandAvailable = false;
9
10
@@ -110,21 +111,29 @@ void mfrc522Read()
110
111
}
111
112
mfrc522.PICC_HaltA();
112
113
cooldown = millis() + COOLDOWN_MILIS;
113
- #ifdef DEBUG
114
- Serial.print(F("[ INFO ] PICC's UID: "));
115
- #endif
114
+
115
+ /*
116
+ * Convert RC522 UID into string
117
+ * esp-rfid v1 had a bug where the UID string may miss some '0's. To
118
+ * maintain compatibility, calculate incorrect UID here as well for
119
+ * later checking in case old users exist in the config.
120
+ */
116
121
for (byte i = 0; i < mfrc522.uid.size; i++)
117
- {
118
- uid+=(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
119
- uid+=(String(mfrc522.uid.uidByte[i], HEX));
120
- }
122
+ {
123
+ uid+=(String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : ""));
124
+ uid+=(String(mfrc522.uid.uidByte[i], HEX));
125
+ v1uid+=(String(mfrc522.uid.uidByte[i], HEX));
126
+ }
121
127
rfidState = cardSwiped;
122
128
123
129
#ifdef DEBUG
130
+ Serial.print(F("[ INFO ] PICC's UID: "));
124
131
Serial.print(uid);
125
132
#endif
133
+
126
134
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
127
135
type = mfrc522.PICC_GetTypeName(piccType);
136
+
128
137
#ifdef DEBUG
129
138
Serial.print(" " + type);
130
139
#endif
@@ -288,10 +297,27 @@ void rfidProcess()
288
297
}
289
298
290
299
File f = SPIFFS.open("/P/" + uid, "r");
300
+
301
+ /*
302
+ * If the file was not found then this is an unknown user, so no more
303
+ * processing to be done. However, we do a secondary check here to see
304
+ * if an old esp-rfid v1 uid exists and if so use that.
305
+ */
291
306
if (!f)
292
307
{
293
- processingState = unknown;
294
- return;
308
+ /* Test to see if there was a uid in v1 format */
309
+ f = SPIFFS.open("/P/" + v1uid, "r");
310
+ if (!f)
311
+ {
312
+ processingState = unknown;
313
+ return;
314
+ }
315
+ uid = v1uid;
316
+ #ifdef DEBUG
317
+ Serial.print(" (found uid in v1 format: ");
318
+ Serial.print(v1uid);
319
+ Serial.print(")");
320
+ #endif
295
321
}
296
322
297
323
size_t size = f.size();
@@ -494,6 +520,7 @@ void cleanRfidLoop()
494
520
currentInput = "";
495
521
type = "";
496
522
uid = "";
523
+ v1uid = "";
497
524
rfidState = waitingRfid;
498
525
processingState = waitingProcessing;
499
526
ledWaitingOff();
0 commit comments