Sequential eeprom saving and saving to the oldest entry first?

Hi I have a sketch which looks up MAC addresses of wifi phones connected to my esp8266. I need to have those MAC addresses saved to these bytes on my EEPROM.

I figured out how I can save if just one phone is connected. But my newbee issue is I don't know how to save them if there is 2 or 3 or 4 phones connected (4 is max connections so it will be 1, 2, 3, or 4 current connections)

Things I'm trying to accomplish:

If MAC address is already saved don't do anything
if not
Overwrite the OLDEST entry to the EEPROM
and do the same for 2nd 3rd and 4th connected MAC if 2nd, 3rd, or 4th are even connected.

// FIRST MAC SHOULD SAVE HERE
        EEPROM.write(11, stat_info->bssid[0]);
        EEPROM.write(12, stat_info->bssid[1]);
        EEPROM.write(13, stat_info->bssid[2]);
        EEPROM.write(14, stat_info->bssid[3]);
        EEPROM.write(15, stat_info->bssid[4]);
        EEPROM.write(16, stat_info->bssid[5]);

// 2ND MAC SHOULD SAVE HERE
        EEPROM.write(21, stat_info->bssid[0]);
        EEPROM.write(22, stat_info->bssid[1]);
        EEPROM.write(23, stat_info->bssid[2]);
        EEPROM.write(24, stat_info->bssid[3]);
        EEPROM.write(25, stat_info->bssid[4]);
        EEPROM.write(26, stat_info->bssid[5]);

// 3RD MAC SHOULD SAVE HERE
        EEPROM.write(31, stat_info->bssid[0]);
        EEPROM.write(32, stat_info->bssid[1]);
        EEPROM.write(33, stat_info->bssid[2]);
        EEPROM.write(34, stat_info->bssid[3]);
        EEPROM.write(35, stat_info->bssid[4]);
        EEPROM.write(36, stat_info->bssid[5]);

// 4TH MAC SHOULD SAVE HERE
        EEPROM.write(41, stat_info->bssid[0]);
        EEPROM.write(42, stat_info->bssid[1]);
        EEPROM.write(43, stat_info->bssid[2]);
        EEPROM.write(44, stat_info->bssid[3]);
        EEPROM.write(45, stat_info->bssid[4]);
        EEPROM.write(46, stat_info->bssid[5]);

Here is the sketch which looks up the MAC addresses

/*
 * Getting MAC and IP Address of Connected devices to ESP8266 
 * with Soft AP Mode
 */
 
#include <ESP8266WiFi.h>
 
extern "C" {
  #include<user_interface.h>
}
 
/* configuration  wifi */
const char *ssid = "MYSSID";
const char *pass = "password";
 
void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  
  WiFi.softAP(ssid,pass);
  
  IPAddress myIP = WiFi.softAPIP();
  
  Serial.print("AP IP address: ");
  Serial.println(myIP);
}
 
void loop() {
  delay(5000);
  client_status();
  delay(4000);
}
 
void client_status() {
 
  unsigned char number_client;
  struct station_info *stat_info;
  
  struct ip_addr *IPaddress;
  IPAddress address;
  int i=1;
  
  number_client= wifi_softap_get_station_num();
  stat_info = wifi_softap_get_station_info();
  
  Serial.print(" Total Connected Clients are = ");
  Serial.println(number_client);
  
    while (stat_info != NULL) {
    
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
      
      Serial.print("client= ");
      
      Serial.print(i);
      Serial.print(" IP adress is = ");
      Serial.print((address));
      Serial.print(" with MAC adress is = ");
      
      Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
      Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");
      
      stat_info = STAILQ_NEXT(stat_info, next);
      i++;
      Serial.println();
    }
    
  delay(500);
}

connected to my esp8266. I need to have those MAC addresses saved to these bytes on my EEPROM.

Keep in mind that the EEPROM.flash on an ESP8266 is guaranteed for only 1000 writes (i think it's per cell though), Doing what you want to achieve does require a write to the EEPROM for every connection. If you want to make sure that the oldest is overwritten, that means that even if it is an existing address you must update either the time of last connection, or at least some kind of counter. Why do you need these addresses stored in EEPROM ? are you switching the ESP off and back on again all the time ? If you just want to keep track of which devices have connected, you might be better of with storing more than just 4 addresses.

And just now i saw your other thread. Anyway i do something similar storing to the EEPROM for Wifi networks the ESP has connected to successfully. I store the network, the password as a list. I don't bother checking to see which was the last connected network (or their sequence for that matter) i just have an Area in EEPROM reserved for them. i use about 120 bytes and figure that should be enough. though i can remove networks from the list manually if i want. So rather than keeping track of how many networks are in there and where they are i simply put a terminator right at the start of my list (the ssid & password have their own terminator of course) and for this i use the ESP-chip-id, i compare the chip id to the first 3 bytes in my list, if that doesn't match i'll start loading in ssid's until i find the chip-id. Not relevant to your plan but for completions sake, i then compare the loaded list to any of the networks found in the scan and connect to any i found.
But what is relevant, is that you are using 6 bytes to store a MAC address, which is actually only 3 bytes long, you are writing 3 bytes as HEX and then store the 6 resulting characters in EEPROM. That is inefficient.
Anyway i think you will be better of taking a larger section of EEPROM (standard EEPROM can go up to 4kb and using SPIFFS you have a lot more space..) and writing data into that than overwriting the same cells all the time.

1000 times rewrite is plenty for what I'm doing with this gadget but people say its more like 10,000 per cell who knows

I just figured out how to do it, after every save I also save the last cell written to to an extra cell so that I can keep track for when I come back or a new MAC client connects to the device.

I only need last 4 MACs for this device even 2 or 3 would be fine.

As for the spiffs I'm totally new to writing C code, everything I know has been googled lol so spiffs is stills something I need to do quite a bit of googling on. Here is what I ended up writing, do put your two cents in it

#include <ESP8266WiFi.h>
#include <EEPROM.h>      // save to memory

int passFlag = 0;
int addr = 0;  // first address to write to on eeprom, saved location from last time

extern "C" {
#include<user_interface.h>
}

/* configuration  wifi */
const char *ssid = "SSID";
const char *pass = "";

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");

  WiFi.softAP(ssid, pass);

  IPAddress myIP = WiFi.softAPIP();

  EEPROM.begin(32);

  Serial.print("AP IP address: ");
  Serial.println(myIP);
}

void loop() {
  delay(5000);
  client_status();
  delay(4000);
}

void client_status() {

  unsigned char number_client;
  struct station_info *stat_info;

  //  struct ip_addr *IPaddress;
  struct ip4_addr *IPaddress;
  IPAddress address;
  int i = 1;

  number_client = wifi_softap_get_station_num();
  stat_info = wifi_softap_get_station_info();

  Serial.print("TOTAL CONNECTED CLIENTS = ");
  Serial.println(number_client);

  while (stat_info != NULL) {

    IPaddress = &stat_info->ip;
    address = IPaddress->addr;

    Serial.print("CLIENT # = ");
    Serial.print(i);
    Serial.println();
    Serial.print("IP  address = ");
    Serial.print((address));
    Serial.println();
    Serial.print("MAC address = ");
    Serial.print(stat_info->bssid[0]); Serial.print(" ");
    Serial.print(stat_info->bssid[1]); Serial.print(" ");
    Serial.print(stat_info->bssid[2]); Serial.print(" ");
    Serial.print(stat_info->bssid[3]); Serial.print(" ");
    Serial.print(stat_info->bssid[4]); Serial.print(" ");
    Serial.print(stat_info->bssid[5]); Serial.print(" ");
    Serial.println();
    Serial.println();


//##################  PART I WROTE  ###############################

    if ((stat_info->bssid[0] != EEPROM.read(1)) && (stat_info->bssid[1] != EEPROM.read(2))
        && (stat_info->bssid[0] != EEPROM.read(7))  && (stat_info->bssid[1] != EEPROM.read(8))
        && (stat_info->bssid[0] != EEPROM.read(13)) && (stat_info->bssid[1] != EEPROM.read(14))
        && (stat_info->bssid[0] != EEPROM.read(19)) && (stat_info->bssid[1] != EEPROM.read(20))) {
      addr = EEPROM.read(0);
      if ((addr != 1)  && (addr != 7) && (addr != 13) && (addr != 19)) {
        addr = 1;
      }
      EEPROM.write(addr, stat_info->bssid[0]);
      addr = addr + 1;
      EEPROM.write(addr, stat_info->bssid[1]);
      addr = addr + 1;
      EEPROM.write(addr, stat_info->bssid[2]);
      addr = addr + 1;
      EEPROM.write(addr, stat_info->bssid[3]);
      addr = addr + 1;
      EEPROM.write(addr, stat_info->bssid[4]);
      addr = addr + 1;
      EEPROM.write(addr, stat_info->bssid[5]);
      addr = addr + 1;
      if (addr >= 25) {
        addr = 1;
      }
      EEPROM.write(0, addr);
      EEPROM.commit();
    }
//#######################  END OF MY CODE ###########################

    stat_info = STAILQ_NEXT(stat_info, next);
    i++;
    Serial.println();
  }
  delay(500);
}