Trying to find MAC address on ESP32 and failing

Hello everyone,

I'm having a persistent issue where I cannot get the MAC address from any of my ESP32 boards. I'm hoping someone has seen this specific problem before.

The Problem:
When I run a basic sketch to get the MAC address, the Serial Monitor always outputs 00:00:00:00:00:00. This happens even on a known-good board that can run other complex sketches (like controlling a FastLED strip).

The Code:
This is the minimal code I am using for the test. I have also tried the esp_base_mac_addr_get() function, but the IDE gives a "not declared in this scope" error.

codeC++

#include "WiFi.h"

void setup(){
  Serial.begin(115200);
  
  WiFi.mode(WIFI_STA);
  
  Serial.println();
  Serial.print("My MAC Address is: ");
  Serial.println(WiFi.macAddress());
}

void loop(){
}

The Output:
This is the full output from the Serial Monitor after pressing the RST button:

codeCode

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4980
load:0x40078000,len:16612
load:0x40080400,len:3480
entry 0x400805b4

My MAC Address is: 00:00:00:00:00:00

What I Have Already Tried:

  • I have tested this on two different ESP32 boards.

  • I have used multiple different USB cables and multiple different USB ports on my computer.

  • In the Arduino IDE Boards Manager, I have completely uninstalled and reinstalled the "esp32 by Espressif Systems" package (using version 3.3.3).

  • I have confirmed that "ESP32 Dev Module" is selected under the Tools > Board menu.

  • I have confirmed the correct COM port is selected and that the upload completes successfully.

My System Information:

  • *Operating System: (Windows 11) *

  • *Arduino IDE Version: (2.3.6) *

Does anyone have any idea what could be causing the Wi-Fi hardware to fail to initialize in this way across multiple boards? Thank you in advance for your help.

You might want to check the outstanding issues on the ESP32 core for previous reports and workaround or solutions.

1 Like

I have had similar problems, but using the following may help to show MAC address in the Serial Monitor, works for me on ESP32:

  auto stringhexcode = Network.macAddress();
  Serial.println("Uppercase MAC address=");
    stringhexcode.toUpperCase();
  Serial.println(stringhexcode);

Sometimes you need a small delay to allow wifi to initialize

#include <WiFi.h>

void setup(){

 Serial.begin(115200);

  WiFi.mode(WIFI_MODE_STA);
  while (WiFi.status()==WL_STOPPED){}
  Serial.print("My MAC Address is: ");
  Serial.println(WiFi.macAddress());

}

void loop()
{

}