2

I'm using Raspberry Pi Model B+. I'm new to the RPi and I don't really know the search terms for my question.

I have four RFID readers connected to the four USB ports of my RPi. I wanted to know if there's a command in python to know which out of the four readers/USB ports the data is coming in. The RFID reader prints hex or oct number with or without carriage return upon placing an RFID card.

The closest I get is alphacharlie's answer here (Capturing serial number of 2 USB RFID Reader in python (PI+2 RFID (Mifire RFID))) talking about /dev/input/keyboard. He/she said,

If one of your readers is of the HID type, then you can look for the input at some variation of /dev/input/keyboard

I think my reader is of the HID type, but I don't quite understand what "you can look for the input at some variation of /dev/input/keyboard" means.

Edit: I'm using USB MIFARE™ Reader SL040A (http://www.stronglink-rfid.com/en/rfid-readers/sl040a.html)

1 Answer 1

1

I'm looking at the same problem with (currently) a single but different RFID USB (HIDevice) reader. It presents a 10-digit number and a (CR +?) LF (from the tag read) as if it was typed in at a keyboard. I made some headway with adding a new rule 10-local.rules to the /lib/udev/rules.d/ system to add a known name as a symlink in the /dev directory:

ACTION!="add|change", GOTO="end"

# Adding a standard symbolic link for RFID scanner, ideally will use to isolate from keyboard
SUBSYSTEM=="usb", ATTRS{idVendor}=="vvvv", ATTRS{idProduct}=="pppp", ATTRS{serial}=="############", SYMLINK+="rfid#", TAG+="rfid", OPTIONS+=last_rule

LABEL="end"

In your case you will need to edit vvvv and pppp to be the vendor and product id of the readers and then copy this three more times and replace ############ with the individual serial numbers of your devices (I assume they all all the same device!) and the # in rfid# with I suggest a number from 1 to 4 or (perhaps a "_location" for each device). Now, when each RFID USB device is plugged in it is detected and the rfid# symlink will appear and become available as, say /dev/rfid1 to /dev/rfid4 respectively.

The complication is that the input will still get treated as if it was typed at a keyboard - which will be treated as username entry on the local console as if there is a user trying to log in locally on the Pi. Further work is needed - possibly to get the device(s) to be ignored as keyboards and have a daemon to open those devices and monitor the input...

A (stupidly insecure) use of an RFID device (as a keyboard) as an access device:

As I happen to know the numbers produced by the tags I have and I only have one reader, I was able to create users with the same usernames as those numbers (sudo adduser can be a bit iffy about this, I think I had to use the --force-badname option). By disabling a password for that "user" and replacing the login shell by a shell script I could get that script to be run every time the relevant tag was presented to the reader - excerpt from in /etc/passwd:

...
1234567890:x:110:65534::/home/1234567890:/usr/local/bin/door_unlock
...

1234567890 is NOT the number of one of my tags...!

Whilst this works it is not secure - anyone getting even remote access to the Pi could try a login (via any enabled telnet/rlogin/ssh system) with the given number and they would succeed (no password remember!) and cause that door_unlock script to run.

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.