Yes, the code as presented works. The problem is that after a while of constant disconnect/reconnects, its like the client gets tired and halts.
Halts where? What is the last line you see in the serial monitor after the halt? That is why the additional serial prints in mine. Is the last line "connected" or "disconnected"?
edit: I failed to see this. My bad!
I can scan a card and it'll read it, report to the API and act on the API's response as expected. If it's in unlock mode, it'll poll the API as expected.
The issue is that after a minute or so of sitting "idle" (not actively working on a received card) the polling will arbitrarily stop. When it does, the card reader doesn't see a new card and I stop seeing the polls go out.
Please post your setup function.