HID RFID and ARDUINO etherten

I have made a little project with 2 RFID readers from HID and 2 outputs for a door.
Now all my tags are hardcoded into the arduino etherten.(see also my project in attachment).

What a would like to do is to put all my valid tags onto an micro SD card instead of hard coded into the arduino program, so everytime a tag is readed the arduino checks if the tag is on the sd card.

I would also like to add and remove tags from the micro sd card via ethernet, how could i do that.

Can someone help me with this ?
I am not so verry good in programming, but after a while i will understand.

Kind regards
Geert

HID_RFID_ACCESS_ETH.ino (9.61 KB)

The first part is simple, just have a look at the native SD card library for simple read/write operations.

The 2nd part involving editing over ethernet could be a bit complex but achievable. Complex because the SD Card and the ethernet shield both use the same SPI communication port. Just make sure to open and close the files on the SD card everytime you read/write.

Hello Bachna,

I will try the first part today, but after that can you assist me a little bit with the second part ?

Regards

Hello,

I can read a file test.txt, but i need to read the file line by line and compare the value of temp = 33333333 with a line that is stored on test.txt file. If temp equals the value on test.txt the badge is accepted

Contest of test .txt :

11111111 22222222 33333333 44444444

Who can help me a little bit with that ?

Who can help me a little bit with that ?

Depends. What have you tried?

Hi already try this :

#include <SD.h>

File myFile;
volatile unsigned long Temp = 0;

void setup()
{
Temp = 33333333;
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print(“Initializing SD card…”);
pinMode(10, OUTPUT);

if (!SD.begin(4)) {
Serial.println(“initialization failed!”);
return;
}
Serial.println(“initialization done.”);

myFile = SD.open(“test.txt”);
if (myFile) {
Serial.println(“test.txt:”);

// read from the file until there’s nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn’t open, print an error:
Serial.println(“error opening test.txt”);
}
}

void loop()
{
// nothing happens after setup
}

This reads the entire file, but i need to compare if Temp = 33333333 is in the text file, if so, then print on the screen TAG : 33333333 acces ok

This reads the entire file

And does nothing more than send it to the serial monitor. You need to store the data in an array. When the end of record marker is read, don't store that (there may be two - \r and \n, or just one of the pair). Instead, compare the value in the array as a string to the scanned tag as a string.

Why are you converting the scanned tag to a long, anyway?

Mmmmmm, can you help me with this, i doesnt understand what you mean.

i doesnt understand what you mean.

Which part don't you understand?

    while (myFile.available()) {
       Serial.write(myFile.read());

This code reads one byte at a time from the file, and sends it to the serial monitor. You want to store it in an array, instead.

Ok that i understand thats byte par byte, but i don't know how to read the first line into a variable and after check with "Temp" i need to read the second line of the text file and so on .

Regards Geert

    char record[80];
    byte index = 0;
    while (myFile.available())
    { // Down here where it belongs
       int aChar = myFile.read();
       if(aChar == '\n' || aChar == '\r')
       {
          // Record is complete. Do something with it

          index = 0;
          record[index] = '\0';
       }
       else
       {
           record[index++] = aChar; // Store the character
           record[index] = '\0'; // Append a NULL
       }
    }

Now, it is your turn. You figure out how to convert record to a long (strtol()) and compare it to the scanned tag.

You still haven't explained why you are converting the scanned tag to a long.