I'm trying to read the UID of MIFARE 13.5Mhz cards with MFRC522 lib and I have defined the following function for it.
void getUID() {
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
Serial.println("Scanned PICC's UID:");
tag = "";
for (byte i = 0; i < mfrc522.uid.size; i++)
{
tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
tag.concat(String(mfrc522.uid.uidByte[i], HEX));
}
tag.toUpperCase();
Serial.println(tag);
mfrc522.PICC_HaltA(); // Stop reading
}
}
this function works perfectly fine in void loop() but when I call it in the following web request my esp8266 crashes.
controlserver.on("/searchuid", HTTP_POST, [](AsyncWebServerRequest *request){
transmit = request->arg("idcode");
if (request->hasArg("configmodule")) {
File file = SPIFFS.open("/inputString.txt", "r");
if (!file) {
Serial.println("Failed to open file");
return;
}
getID();
delay(500);
Serial.println(tag);
String content = file.readString();
if (content.indexOf(tag) >= 0) {
Serial.println("Found search string");
} else {
Serial.println("Did not find search string");
}
}
});
and I cannot understand why, any help will be appreciated.