Time attendance with esp8266/esp32 - best way to save data

I'm working on building a time attendance device using ESP8266 or ESP32 with an RFID module connected to it through UART (TX/RX). I want to implement a local database or JSON file or array or anything else to register users and record enrollment datetime.

Assuming I have two data structures:

struct User {
  int userID;
  char userName[50];
  long rfid_ID;
  int btid;
  unsigned long registeredDateTime;
};

struct Enrollment {
  int enrollID;
  int userID;
  char type[10];
  unsigned long enrollTimeStamp;
};

I will use functions to add, edit, and delete users:

registerUser(1, "Jon Smith", 123456678, 12344);
editUser(1, "Jon Smith", 123456678, 12344);
deleteUser(1);

And a function to enroll users:

enrollUser(123, 1, "rfid", 1704633458);

I want to ensure that this data is persistent even if power is cut.

For user data, it should be possible to add, edit, or delete, with the changes staying on the device.

Enrollment data ill delete them after syncing with the server.

What's the best way to save this data, what structure to use and where should I save it for the best performance and reliability?

on an ESP32 you could use the Preferences API to save your data

a tutorial : ESP32 Save Data Permanently using Preferences Library | Random Nerd Tutorials

do you need to keep a log of all attendance or just the last checkin ?

--
side note

is that the ID of the RFID card? is long the right type then?

i read somewhere that there is problem if u rewrite or write many times, is this correct?
because all the time people will make new enrollment and at the end of day ill send them to server and delete from device


and to create users i need to make a namespace and add keys for every user right? not like array or map-like structure

  user_1_name=Jon Smith
  user_1_rfid=123456678
  user_1_btid=12344
  user_1_registeredDateTime=123456789

  user_2_name=Alice Johnson
  user_2_rfid=987654321
  user_2_btid=56789
  user_2_registeredDateTime=123456790

  user_3_name=Bob Doe
  user_3_rfid=111223344
  user_3_btid=54321
  user_3_registeredDateTime=123456791

flash memory has a maximum number of writes for once cell location. after ~10,000 to 100,000 writes you can start having issues (depends on type of flash you use)

The mechanism underlying the Preferences is based on NVS (Non-Volatile Storage) which has wear levelling functionality ( Details are here)

if you have a large enough partition, you could be fine for a few years.

it depends on how many cards you want to manage and if you want to keep an history on device or just the last checkin

what if i have aprox of 100kb of data as history

what if i use a sd card, is that better solution and is there same mechanism with key values or i can use different way of storing data

I would use an FRAM - the example shows using a UNO but would work OK with a ESP8266

if you are worried, you could add FRAM ➜ Each byte can be read/written 10,000,000,000,000 times so you don't have to worry too much about wear leveling

--

you would have to clarify exactly what's kept on the ESP32 (for each user and how many users do you manage)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.