Can't get second EEPROM.read for loop to print to serial

I’m trying to write a sketch which first writes bytes to the eeprom for IP address and MAC address from two arrays of bytes, then recall these values from EEPROM and print them to the serial monitor.

This is running on a Mega 2650.

I have two for loops writing bytes to the eeprom, one for IP and one for MAC.

There are then two for loops which are meant to recall these bytes and print them with a little bit of formatting.

However when the sketch runs, the for loop recalling the MAC address works fine and the line "IP = " prints, but the IP address values never print.

As far as I can tell my for loop for writing the bytes to eeprom is correct (it matches the MAC address write for loop). Been tearing my hair out with this all day now!

Any help would be much appreciated, thank you!

#include <EEPROM.h>


//MAC VARIABLES ---------------------------------------------------
int macEepromAddress = 0; //start address mac address bytes in eeprom
int macBytes = 5; //number of bytes in mac address
byte macValue;


byte macOct0 = 0xDE; //first octet of mac
byte macOct1 = 0xAD; //second octet of mac
byte macOct2 = 0xBE; //third octet of mac
byte macOct3 = 0xEF; //fourth octet of mac
byte macOct4 = 0xFE; //fifth octet of mac
byte macOct5 = 0xED; //sixth octet of mac



byte macInput[6] = {macOct0, //array combining all mac octets for use in
                    macOct1, //for loop which writes bytes to eeprom
                    macOct2,
                    macOct3,
                    macOct4,
                    macOct5
                   };


// IP VARIABLES --------------------------------------------------
int ipEepromAddress = 6; //start address of ip address bytes in eeprom
int ipBytes = 4; //number of bytes in ip address
byte ipValue;

byte ipOct0 = 10; //first octet of ip address
byte ipOct1 = 0; //second octet of ip address
byte ipOct2 = 0; // third octet of ip address
byte ipOct3 = 200; //fourth octet of ip address

byte ipInput[5] = {ipOct0, //array combining all ip octets for use in
                   ipOct1, //for loop which writes bytes to eeprom
                   ipOct2,
                   ipOct3
                  };
void setup() { //--------------------------------------------------
  // put your setup code here, to run once:
  Serial.begin(9600);


  //i = start address of eeprom bytes
  //if i less than or equal to number of bytes in mac address
  // write each byte of mac address to incrementing address in eeprom
  for (int i = macEepromAddress; i <= macBytes; i++) {
    EEPROM.write(i, macInput[i]);
  }

  for (int i = ipEepromAddress; i <= ipBytes; i++) {
    EEPROM.write(i, ipInput[i]);
  }



  Serial.print("MAC = ");
  for (int i = macEepromAddress; i <= macBytes; i++) {
    macValue = EEPROM.read(i);
    if (i <= macBytes - 1) {
      Serial.print(macValue, HEX);
      Serial.print(":");
    } else if (i >= macBytes) {
      Serial.print(macValue, HEX);
    }
    delay(100);
  }
  Serial.println();

  Serial.print("IP = ");
  for (int i = ipEepromAddress; i <= ipBytes; i++) {
    ipValue = EEPROM.read(i);
    if (i <= ipBytes - 1) {
      Serial.print(ipValue, DEC);
      Serial.print(".");
    } else if (i >= ipBytes) {
      Serial.print(ipValue, DEC);
    }
    delay(100);
  }

}

void loop() { //---------------------------------------------------
  // put your main code here, to run repeatedly:

}
for (int i = ipEepromAddress; i <= ipBytes; i++)

This evaluates to int I = 6; i <= 4; i++, so the for does not execute ( 4 is already less than 6).

Maybe:
for (int i = ipEepromAddress; i <= ipBytes + ipEepromAddress; i++)

for (int i = ipEepromAddress; i < ipBytes + ipEepromAddress; i++) {

To save from address 6 through address 9.

And

EEPROM.write(i, ipInput[i - ipEepromAddress]);

Since you want the address to start with ipEepromAddress (6) and save or recover the ipInput array elements starting with element 0.

if (i <= ipBytes - 1) {
      Serial.print(ipValue, DEC);
      Serial.print(".");
    } else if (i >= ipBytes) {
      Serial.print(ipValue, DEC);
    }

This will not work the way that you want, either, because of the actual values of i again.

if (i <= ipBytes - 1) {

i starts out as ipEepromAddress (6) so will never be less than ipBytes - 1 (3).

byte macOct0 = 0xDE; //first octet of mac
byte macOct1 = 0xAD; //second octet of mac
byte macOct2 = 0xBE; //third octet of mac
byte macOct3 = 0xEF; //fourth octet of mac
byte macOct4 = 0xFE; //fifth octet of mac
byte macOct5 = 0xED; //sixth octet of mac

byte macInput[6] = {macOct0, //array combining all mac octets for use in
                    macOct1, //for loop which writes bytes to eeprom
                    macOct2,
                    macOct3,
                    macOct4,
                    macOct5
                   };

All of that seems to be a complicated way to say:

byte macInput[] = {0xAD,0xBE,0xEF,0xFE,0xED};

Is there a reason for the extra complexity?

Same with the IP address.

Fantastic, thank you!

Seems it was my misunderstanding of the syntax of for loops. The variables happened to make it work for the mac address.

Re the complex code at the start, yeah I figured that was a long winded way of going about it. I'm pretty new to this so seeing it laid out like that just made it easier to comprehend at this stage.

Thanks again!