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));
  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");
    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.

1 Answer 1


Under "Important Things To Remember" in the ESPAsyncWebServer README:

You can not use yield or delay or any function that uses them inside the callbacks

Your code calls delay() in the callback, and calls functions that you cannot know do not call delay() or yield().

You need to rewrite your code to follow the instructions in the web server's documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.