pokusew / nfc-pcsc

Easy reading and writing NFC tags and cards in Node.js
MIT License
527 stars 130 forks source link

Detect Reader #116

Open lottafederico opened 2 years ago

lottafederico commented 2 years ago

I'm using the ACR122u with a raspberry pi, the library works like a charm but when I reboot the Pi and the application start (automatically with Pm2) it doesn't detect the reader. The only way is to unplug and plug the reader again. I was using uhubctl library to phisically turn on/on the usb ports simulating the unplug but the Pi Zero doesn't support this feature. I've tried to use the node-pcsclite library and call pcsc.close() but doesn't work. The pi actually detect the reader (test done with lsusb). Any suggest? Thanks

atoikka commented 2 years ago

@lottafederico by any chance, did you find out anything? I am currently seeing the same issue periodically. The next time I encounter, I'll try to look at pcsc_scan and see what it reports.

mirkogeest commented 2 years ago

I have exactly the same issue, but with pi 3. Did you manage to find a solution to this?

atoikka commented 2 years ago

I found out that it is likely a ACR122U reader firmware issue. I was able to find some references such as this and verified from the pcscd logs that it was unable to enumerate the device unless a complete power reset (i.e. replug of RPi power or the ACR122U itself) was done. I also experimented running pcscd on the foreground (with verbose logging) and issuing USB reset to the device - the results were odd, the ACR122U was functioning after about 20% of all resets. We briefly discussed the idea of using a GPIO pin to drive the device's power supply, but found a good delivery option for the ACR1252U. I can confirm that the ACR1252U survives USB resets (no power loss) properly, and advise towards using it.

mirkogeest commented 2 years ago

For our topology we finally found a solution, as it is not an option to unplug the usb physically. We use a balena docker image, so we added the uhubctl app, which allows turn usb off and on, to the Dockerfile.template:

RUN install_packages pcscd libusb-dev libpcsclite1 libpcsclite-dev dh-autoreconf python3 uhubctl g++

And at package.json we start this way:

  "scripts": {
    "start": "uhubctl -l 1-1 -p 2 -a off && uhubctl -l 1-1 -p 2 -a on && pcscd && node server.js"
  }

It's working like a charm!