My plan was to store rfid tags in the EEPROM that are to be banned. I would have to use 3 or 4 address as tag id's are 8 characters. While that makes it more complex, that's not my main issue. It's taking around 5 to 7 seconds to loop through all 1024 addresses. Doesn't seem like a lot but if you are waiting for a gate to open, that's long enough to wonder if your key worked and keep swiping it. so i'm not sure where to go from here. Is there a better place to store the data? using variables takes app memory and is volatile. is there a better logical way I can look for the data?
But I don't really have code at the moment. An example of an RFID ID would be "AE 79 4F A3". the way I see it in code (i'm still trying to wrap my head around working with bytes so i convert it to string, memory intensive i know) is "17412179163"
so basically, I need to store "17412179163" somewhere, along with other like numbers, and loop through the list of numbers to see if my "current number" is in the list.
in the future I can simply write them to a web server which will store them in a database and simply report yes or no if its in the list or not. but for the moment i need to have a stand alone setup.
That is 4 bytes per tag. 1k bytes give up to 250 tags. You would linearly scan through the tags in the eeprom until you get a hit or hit the end marker (say 0xFFFFFFFF) so the time taken would depend on how many tags were registered in the eeprom.
I have some code now. I don't think its actually taking this long, I think its printing to serial that is taking the time.
int FindFirstAvailableEEPROMSetOf8(){
for (int i = 0; EEPROM.length(); i = i + 8){
if(EEPROM.read(i)== 255){
return(i);
}else if(i > EEPROM.length()){
return(32767);
}
}
so, i guess my question becomes, Is there a better way to do this?
I can't paste the whole sketch as its too big and i don't know if pastebin is allowed. But everything else is all related to rfid card reading and not really the question here.
#include <SPI.h>//include the SPI bus library
#include <MFRC522.h>//include the RFID reader library
#include <EEPROM.h>
those are my includes.
void loop() {
int address = FindFirstAvailableEEPROMSetOf8();
Serial.println(address);
}
int FindFirstAvailableEEPROMSetOf8(){
for (int i = 0; EEPROM.length(); i = i + 8){
if(EEPROM.read(i)== 255){
return(i);
}else if(i > EEPROM.length()){
return(32767);
}
}
That is where i'm looking for available sets of 8 blocks of memory.
String txt; //This is where we store block 2, the password
String uid; //This is where we read the tag id from the red card
String compare = "17412179163";//currently using tag's id, for testing.
//get card uid to see if its in eeprom aka banned
Serial.println("Scanned PICC's UID to see if its banned:");
for (int i = 0; i < mfrc522.uid.size; i++) {
uid = uid + (byte)mfrc522.uid.uidByte[i];
}
That bit is how i'm getting the UID. it comes in a decimal form. I think part of the ascii code. eventually I will learn how to deal with just the byte data not what is output to casting to string.
Correct. I can only ban 128 cards at a time. but once that card gets used, its deactivated and then removed from the banned list. so itl only be an issue if 128 people don't turn in their card.
This isn't the best way of doing it. but without more storage, i'm not sure if there is a best way.
Compare it with a new street and somebody builds a new house (connect something to the bus). Next somebody else also builds a house. Houses have house numbers, those are the addresses on the bus.
And next there is the protocol that says how to deliver a parcel (data) to a specific house address or fetch a parcel from a specific house. address.