I use an ESP32 to scan RFID cards and would like create a timeout per card.
My idea is to store the UID of the card (String value) with the current time in millis.
When i scan a card it needs to check if the array has a value with the UID and if not, add the UID with the current millis + timout.
After the timout (say 30 seconds) it could remove the value from the array to keep it small.
In pseudo it would look like this:
list = {
'1425342': 38289,
'1883028': 40192,
'8382917': 42148,
}
...
I would also need to be able to see if card UID 1883028 already is in the list and if the millis for that value is smaller than current millis + timeout.
I am not sure which is the best approach, but i thought something like a struct:
typedef struct
{
String cardUid;
unsigned long time;
} registrationHistory;
But i need to define an array of "registrationHistory" with a certain length. In my case the length needs to be variable and i need to be able to search in the array, so i am not sure if this is the way i should go
I will search for linked list, but wouldn't an array as big as it ever could be not give me problems in the end?
The device will "never" turn off and the number of cards that are scanned are increasing every day.
I assume a huge array will take RAM? (sorry if i am wrong)
I wouldn't recommend a linked list on a memory-constrained AVR unit, but you're on an ESP32. Memory management is much less constrained.
However, the array option also works, as long as you limit the number of active cards, which is effectively your 30-second boundary. Just set your IDs to a known flag, like 0, when they're freed up, and can be used. It matters little in this case, but in the more general case a linked list would be the design preference.
If you need to keep the IDs around(for example, you're maintaining a list for future reference, or have a list of allowed visitors), then making your struct a little more complex is an option, too.
Thanks, but i still don't get how i can do this the most efficient way
I cannot see a lot of information how to create a "2d array" out of a vector and be able to search in it
I do a lot of programming in PHP and there a 2d array (or object) is a list of key, value combination.
There i can find a pair via the key or value so a thought it could be the same here.
In this case i don't know how to link the card UID with the time in millis