Issue with WiFi.macAddress() and WiFi.softAPmacAddress() on ESP32 with Arduino Core v3.2.0

Hi everyone,

I’m using the WiFi.macAddress() and WiFi.softAPmacAddress() APIs to retrieve the MAC addresses on ESP8266 and ESP32.

On the ESP8266, both APIs work correctly and return the expected MAC addresses.

On the ESP32, these APIs work fine when using the Arduino core version v1.0.6, but after updating to v3.2.0, both functions return all zeros (e.g., 00:00:00:00:00:00).

Has anyone else experienced this issue on ESP32 with Arduino core v3.2.0? Is this a known bug or is there a workaround?

Thanks in advance!

Topic moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Have you checked the Migration doc? There are a few issues with the implementation of Board 3.x

It's failing the first if() statement of this function in NetworkInterface.cpp. Unfortunately, I don't know what those checks are or how to fix them. You can report it as an issue on the GitHub Page.

uint8_t *NetworkInterface::macAddress(uint8_t *mac) const {
  if (!mac || _esp_netif == NULL || _interface_id == ESP_NETIF_ID_PPP) {
    return NULL;
  }
  esp_err_t err = esp_netif_get_mac(_esp_netif, mac);
  if (err != ESP_OK) {
    log_e("Failed to get netif mac: 0x%04x %s", err, esp_err_to_name(err));
    return NULL;
  }
  return mac;
}

Hi @sandeepkumar_konkumutti. I think it is explained here:

https://github.com/espressif/arduino-esp32/issues/9509#issuecomment-2054171612

since the network refactoring, macAdress comes from the interface and you are asking for it before you have started that interface. Network.macAddress gives you the base MAC of the ESP chip.

https://github.com/espressif/arduino-esp32/issues/9509#issuecomment-2054178644

By far the best way is to use the new network interfaces:

// Get the base MAC of the ESP chip (works always)
Network.macAddress(mac);

// Get the MAC address of WiFi STA (must first start interface)
WiFi.STA.begin();
WiFi.STA.macAddress(mac);

// Get the MAC address of WiFi AP (must first start interface)
WiFi.AP.begin();
WiFi.AP.macAddress(mac);

// Get the MAC address of ETH (must first start interface)
ETH.begin();
ETH.macAddress(mac);

So this means it was an intentional breaking change, not a bug. Unfortunately the developers were not kind enough to document the change.