Connecting to DHCP

Hi! So my problem is, I read the MAC address from an another program and then I write it to the EEPROM, restart the Ardunio and it should connect to DHCP, but it does not. Every data seems to be OK.
Heres my MAC reading:

unsigned int imac[6] = { 0 };
sscanf(readedData +21, "%02x%02x%02x%02x%02x%02x", &imac[0], &imac[1], &imac[2], &imac[3], &imac[4], &imac[5]);
            Serial.println("IMAC: ");
            for (int i = 0; i < 6; i++) {
              Serial.println(imac[i], HEX);
            }

The writing to the EEPROM:

//char MACADD[] = { 0x30, 0xAE, 0xA4, 0x07, 0x0D, 0x64 }; If I use this, instead of imac, it connects properly after restart.
EEPROM.write(EEPROM_MAC0, imac[0]);
              EEPROM.write(EEPROM_MAC1, imac[1]);
              EEPROM.write(EEPROM_MAC2, imac[2]);
              EEPROM.write(EEPROM_MAC3, imac[3]);
              EEPROM.write(EEPROM_MAC4, imac[4]);
              EEPROM.write(EEPROM_MAC5, imac[5]);

EEPROM.write(EEPROM_firstRun, 0);
              //DHCP = true;
              EEPROM.write(EEPROM_dhcp_address, 1);
resetFunc(); //Resetting the Arduino

And the connection in setup():

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
Serial.begin(9600);

 
  DHCP = EEPROM.read(EEPROM_dhcp_address); 
  if (DHCP) 
  {
    mac[0] = EEPROM.read(EEPROM_MAC0);
    mac[1] = EEPROM.read(EEPROM_MAC1);
    mac[2] = EEPROM.read(EEPROM_MAC2);
    mac[3] = EEPROM.read(EEPROM_MAC3);
    mac[4] = EEPROM.read(EEPROM_MAC4);
    mac[5] = EEPROM.read(EEPROM_MAC5);

    connectToDHCP(mac);
}

The MAC address seems to be ok, if I write it out for the Serial monitor.

My guess is that the problem is somewhere else in your code. Perhaps if you posted your sketch and told us about your hardware, someone could spot a mistake.

Try to outputs mac to Serial after reading it from EEPROM.
Insert this

Serial.println("MAC: ");
            for (int i = 0; i < 6; i++) {
              Serial.println(mac[i], HEX);
            }

before this line:

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