Skip to content

WiFi.macAddress() returns 00:00:00:00:00:00 before WiFi.begin() #11285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
sans-ltd opened this issue Apr 23, 2025 · 4 comments
Closed
1 task done

WiFi.macAddress() returns 00:00:00:00:00:00 before WiFi.begin() #11285

sans-ltd opened this issue Apr 23, 2025 · 4 comments
Labels
3.0 migration issue relates to migration from 2.X to 3.X version Status: Awaiting Response awaiting a response from the author

Comments

@sans-ltd
Copy link

sans-ltd commented Apr 23, 2025

Board

ESP32-Mini 1U

Device Description

Hardware Configuration

Version

v3.1.1

IDE Name

VSCode

Operating System

Linux

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

  • When calling WiFi.macAddress() before WiFi.begin(), we cannot get the MAC address.
  • With Arduino 2, it worked because it used esp_read_mac() as fallback, if WiFi was not initialized yet.
  • If we call WiFi.begin(), our station does not work correctly, we cannot see the WiFi with another device. In Addition, the WiFiAccessPoint example also does not call WiFi.begin()
  • Reading the MAC address with esp_read_mac(mac, ESP_MAC_WIFI_STA) works fine though, without initializing the WiFi first.

Sketch

setup()
{
  auto mac = WiFi.macAddress();
  // mac is 00:00:00:00:00:00
  // do some magic to generate an SSID
  WiFi.softAP(name.c_str(), passwd.c_str());
  ...
}

Debug Message

-

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@sans-ltd sans-ltd added the Status: Awaiting triage Issue is waiting for triage label Apr 23, 2025
@me-no-dev
Copy link
Member

The network layer has changed. You can call the following APIs to get the STA MAC without connecting to anything

WiFi.STA.begin();
auto mac = WiFi.STA.macAddress();

@me-no-dev me-no-dev added 3.0 migration issue relates to migration from 2.X to 3.X version Status: Awaiting Response awaiting a response from the author and removed Status: Awaiting triage Issue is waiting for triage labels Apr 23, 2025
@me-no-dev
Copy link
Member

To get the base MAC address, you can also do directly:

auto mac = Network.macAddress();

@sans-ltd
Copy link
Author

sans-ltd commented Apr 23, 2025

Yes OK, thanks for the hints. But it is quite unintuitive and breaks with Arduino 2.0 in the behavior.

And it is a real use case to create the SSID from the MAC address when setting up a station, where you normally would not call begin.

@me-no-dev
Copy link
Member

v3 is a major version update that does break some APIs. It is for the best though. Especially in the Network layer :)

And it is a real use case to create the SSID from the MAC address when setting up a station, where you normally would not call begin.

Best to use Network.macAddress() in that case to get the ESP's unique base MAC, from which all other MACs are derived

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 migration issue relates to migration from 2.X to 3.X version Status: Awaiting Response awaiting a response from the author
Projects
None yet
Development

No branches or pull requests

2 participants