π 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: