πŸ” What is a MAC Address?

β€’ A unique hardware address assigned to each network interface on a device.

β€’ The ESP32 has two MAC addresses:

β€’ One for Station mode (STA) – used when connecting to Wi-Fi networks.

β€’ One for Access Point mode (AP) – used when creating its own Wi-Fi network.

🧠 Common Issue

Using this code:

#include "WiFi.h"

void setup() {
  Serial.begin(115200); // Start Serial Monitor
  delay(2000);           // Give it a second to start
  Serial.println("Getting MAC address...");
  WiFi.mode(WIFI_STA); 
  WiFi.disconnect(true);
  delay(1000);
  String mac = WiFi.macAddress(); // Get MAC address
  Serial.println("MAC Address: " + mac);
}

void loop() {
  // Nothing to do here
}

…can sometimes return:

00:00:00:00:00:00

βœ… Reason

β€’ The Wi-Fi interface hasn’t fully initialized yet.

β€’ WiFi.macAddress() is a high-level Arduino wrapper that depends on the internal state of the ESP32 Wi-Fi driver.

βœ… Recommended Solution

Use the ESP-IDF low-level function for MAC access: