PoE MicroMod Ethernet Function Board - how to get hardware MAC address?

Hi there,

as I cannot find anything about it in the hookup guide or in the INO examples - has the named board a unique hardware MAC address and if so, how can I retrieve it in the sketch?

In the provided example, the MAC address is defined in the sketch. This won’t work if I use several of those devices on the same network.

If the board has no unique hardware mac address, I thought about using a random mac address generator, but that of course has its own limitations (need to store generated address in EEPROM for using DHCP IP/MAC assignment). Is there a better solution for this?

Thanks,

Michael

Hi Michael,

The W5500 has no pre-defined MAC address. You do need to generate one externally and write it to the W5500 SHAR register. You will unfortunately need to store the address in your microcontroller code / memory.

Previously, I’ve used random valid addresses generated by the website linked below, and stored them in microcontroller flash (“EEPROM”) memory.

I hope this helps,
Paul

THanks @PaulZC

Unfortunately as I found out meanwhile, it looks like the ESP32 Micromod Processor does not have an EEPROM that I could use to store a generated MAC address persistently.

I did not find anything about EEPROM when using the Micromod Single board along with the ESP32 processor.

Or do I miss something here?

Arduino ESP32 supports EEPROM. Please see the link below.

But, we tend to use LittleFS (Little File System) not EEPROM. You do need to make sure you have defined a flash memory partition for LittleFS / “spiffs”. That’s usually available as standard, but it does depend on your Board definitions. Link below.

Thanks again @PaulZC

Meanwhile I found another solution: the ESP32 has a globally unique 48-bit serial number stored as uint64_t.

It can be retreived with ESP.getEfuseMac() and then converted to a unique MAC address:

uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};

void CreateMacAddress()

{

uint64_t chipid = ESP.getEfuseMac(); // 48-bit MAC

mac[0] = (chipid >> 40) & 0xFF;

mac[1] = (chipid >> 32) & 0xFF;

mac[2] = (chipid >> 24) & 0xFF;

mac[3] = (chipid >> 16) & 0xFF;

mac[4] = (chipid >> 8)  & 0xFF;

mac[5] =  chipid        & 0xFF;

}
1 Like

Nice… I’m stealing that! :laughing:

Best wishes,
Paul

esp_read_mac should work well for you. The convention is to take the Base (WiFi) Address and add 3 to the last octet for Ethernet.

esp_read_mac(yourAddress, 3) does it all in one call…

Links below…

Best wishes,
Paul

https://espressif-docs.readthedocs-hosted.com/projects/esp-idf/en/stable/api-reference/system/system.html#mac-address

https://espressif-docs.readthedocs-hosted.com/projects/esp-idf/en/stable/api-reference/system/system.html#_CPPv412esp_read_macP7uint8_t14esp_mac_type_t

2 Likes