WiFi Base MAC and STA MAC address definition

edwardpangct
Posts: 3
Joined: Sun Mar 03, 2019 10:32 am

WiFi Base MAC and STA MAC address definition

Postby edwardpangct » Wed Mar 13, 2019 12:31 pm

Step 1: During Smartconfig, iOS/Android app shows my ESP32 MAC is XX:XX:XX:XX:65:0C

Step 2: I called the following API after ESP32 connected to TP-Link AP using STA mode.

esp_efuse_mac_get_default ( ) -> XX:XX:XX:XX:65:0C
esp_wifi_get_mac (WIFI_MODE_NULL) -> XX:XX:XX:XX:65:0C
esp_wifi_get_mac (WIFI_MODE_STA) -> XX:XX:XX:XX:65:0D

Step 3: In TP-Link Router Admin page, DHCP records shows my ESP32 MAC is XX:XX:XX:XX:65:0C

Can anyone tell me the MAC address definition and expectation?
Should BASE MAC be equal to STA MAC address?

I read the topic https://www.esp32.com/viewtopic.php?f=13&t=2914
Based on esp32/system_api.c function esp_read_mac ( ) should return Base to STA mode. Why esp_wifi_get_mac looks different?

Code: Select all

    if (esp_base_mac_addr_get(efuse_mac) != ESP_OK) {
        esp_efuse_mac_get_default(efuse_mac);
    }

    switch (type) {
    case ESP_MAC_WIFI_STA:
        memcpy(mac, efuse_mac, 6);
        break;

moxhamj2@gmail.com
Posts: 2
Joined: Sun Jan 19, 2025 11:23 am

Re: WiFi Base MAC and STA MAC address definition

Postby moxhamj2@gmail.com » Sun Jan 19, 2025 11:32 am

#include <WiFi.h> // for wifi

void setup() {
// Initialize Serial for debugging
Serial.begin(115200);
while (!Serial) {
}
Serial.println("Start program.");
printMacAddress(); // this does not display the correct mac address, returns MAC Address: FC:3F:3:0:0:0
WiFi.mode(WIFI_STA); // test if this fixes the issue, ChatGPT said it would but it does not...
printMacAddress(); // this does not display the correct mac address, returns MAC Address: 0:0:0:0:0:0
WiFi.scanNetworks(); // Trigger scan to fully initialize Wi-Fi (hours of debugging to find this...)
printMacAddress(); // this prints the correct mac address, MAC Address: 20:43:A8:63:FD:C8
// chatgpt suggested posting this solution on the internet
}

void loop() {
}

void printMacAddress() {
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC Address: ");
for (int i = 0; i < 6; i++) {
if (i > 0) {
Serial.print(":");
}
Serial.print(mac, HEX); // Also print the byte in hexadecimal to the serial port
}
Serial.println("");
}

Who is online

Users browsing this forum: nopnop2002 and 70 guests