After a very long break from this project, I am starting it back up again. My goal is to interface the MCR-12 reader with an Arduino with an ethernet shield and create a door lock system that will allow people to open a door with a magnetic card, log their entry and also allow management of allow access and logs over the internet.
Started working on the project, although now it has changed a bit. I am going to start with the MCR-12 reader, but will move on to an RFID tag. Why? Working on the project at the MidsouthMakers space today, I was asked what I was working on. When I answered, I was told the group needed a door entry system very similar to what I described, except using RFID instead of Magnetic Card Swipe. I was asked if I wanted to take on the project. So my plan is to get the magnetic card reading version working, then replace the routine to read the card with a routine to read the RFID...killing to projects with one program as it were.
Get an encrypted access file via a web client (see Example)
Send log inf via a web client (get/post commands)
Read Magnetic Card Reader / RFID
Check RFID with Encryped File
Activate Electric Door Strike Remote Unlock Mechanism
Started with the basic Mag-Card reader code found HERE and added code to read an SD card file that I made up with encrypted codes using the MD5 libary. Added the MD5 library found in the Scottmac Arduino Library.
Each part was tested by itself before merging the code, but when I merged the three, the program would crash the arduino. After debugging for some time I think the arduino uno I was using ran out of RAM! I came to this conclusion by remarking out sections of code, running the section remaining then adding back the next section until it stopped working once again. I found it to be crashing at the mag-card reading code. Looking at the code, the author uses a very large buffer (int buffer) but only stores a 1 or 0 in the each element while reading the mag card incoming data. I replaced the array with a char buffer that takes up only one byte per element (instead of two bytes per) and it WORKED.
I am concerned that this code by itself (without even starting the internet code for UDP/DNP or WebClient) takes up over 80% of the flash memory available. I will have to optimize the code to take up much less memory or go to a Mega (which I really do not want to do). But with my experiance with the RAM useage of the Mag-Card code, I am hopeful I can optimize the code! Step 1: change that int array to a boolean. That should simplify the if structure to convert the mag-card data to a string.
Rewrote the mag-card reader code to use a boolean array and modified the if structure, but it only saved a 290 bytes in flash memory.
Ran a test on the MD5 routines. They take up more than 40% of the flash memory! Might have to re-think this a bit.
While testing the above, I also found a security issue with the cardreader code. If a user puts in a valid card, then a user puts in any card, but just taps the card insert switch, the last card number will be returned (obviously the 'buffer' is not cleared correctly). Cleared 'buffer' and filled with 0's. (oh yes also need to mention the original code had to change the cardData clear code to fill cardData with '\0' instead of '\n' or it changed the MD5 hash after the 1st card was read).
Found the same library that had MD5 also has MD2, and that that is MUCH smaller. This MIGHT allow the project to fit on the UNO, but at minimum I can continue to move the project forward.
Finally got back to this project (its been how long?). Experimented with the ID-20 Innovations RFID Reader. The tutorial and sample code was bang on right, so the test was a success. I will have to start the full integration of the system and try to get this project done before the start of the semester.
I am going to try to make it that both the mag-card reader and RFID can be used (maybe with a software switch in the code). Since, by chance my code for the mag-card reader uses pins 2, 3 and 5, and the sample code for the RFID uses pins 13 and 0 this should be fairly easy to do.
Also tested my Relay Board with the Arduino, as I expected it worked fine. Might use a similar circuit to trigger the door plate to unlock the door.