Code not working to read Payload from nfc tag

Hello everyone, I am using esp32 and pn532 nfc sensor and I am trying to read the payload inserted in the tag. I'm using the elechouse/PN532 library and this code worked for a while but now it compiles normally without any console errors, but nothing happens afterwards. Can anyone tell me what could be causing my code not to report an error but not working the way it should? Could it be a problem with the library? Is there another one I can use?

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
#include <NdefMessage.h>
#include <NdefRecord.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);

void setup() {
  Serial.begin(115200);

   Serial.println("LEITOR NFC");
   nfc.begin();
}
void loop() {

  Serial.println("\nApproach the Tag to perform the reading.\n");
 Serial.print("outside if"); 
 if (nfc.tagPresent())
    {
        Serial.print("inside if");
        NfcTag tag = nfc.read();
        NdefMessage msg = tag.getNdefMessage();

        // Get the first record
        NdefRecord record = msg.getRecord(0);
        // Get the payload size
        byte length = record.getPayloadLength();
        // Create byte array big enough for payload
        byte payload[length];
        // Get payload to byte array
        record.getPayload(payload);
        // Convert byte Array to string
        String string = String((char *)payload);
        client.publish("unipam/JOHNNFC", string.c_str());

    }  
}

This is how my console looks when I run the code. Notice that he is not able to enter the "if":

image

Try calling like this...
if (nfc.tagPresent(3000))

This sets a timeout value for the call.

I tried here but the result is still the same :cry:

You sure you have everything connected correctly? tagPresent will return false if it doesn't find anything.

Add this line to the top of the program to get the debug messages...

#define NDEF_USE_SERIAL

I believe the connections are correct, here is how I am connecting everything. Also because this code worked once with things exactly as they are now, I don't know why everything suddenly stopped.

I'm using this kind of tags. And the connection I2C.

About the NDEF_USE_SERIAL, The correct way to use would be the way described in this link? Because I made those modifications but nothing happens

Obs: I printed the "tagpresent" and it is returning 0. Even the tag is close to the reader.

Call begin with
nfc.begin(true)
to get verbose output...

Post what you get.

like this ? Nothing has changed yet.

Do you need pull-up resistors on the I2C lines?

Have you got the DIP switches set correctly for I2C ?

in all the documentation I looked at it said nothing about resistors. But I can't say for sure if they are necessary. The switches are correct too.

Probably not an issue actually as it seems to be detecting the device correctly.

Are you sure that the cards/tags you are using match the device?

The tags I'm using are compatible because when I use the <PN532_HSU.h> library I can read the tag normally, the problem only happens when I try to use the i2c connection and library