Get AP MAC address wihout initializing WiFi

rtborg
Posts: 67
Joined: Wed Oct 23, 2019 6:15 am

Get AP MAC address wihout initializing WiFi

Postby rtborg » Sun Apr 17, 2022 6:38 am

I have an application which uses AP mode for provisioning, and I am required to provide a unique SSID. The AP SSID, default password and some other details are stored in records in the NVS, which are created upon the very first device boot.

I was thinking of using the last six digits of the device MAC in combination with a string for the AP SSID. The logic is:

1. Upon boot, check if "first_run" variable in NVS is existing
2/ If not existing, set it and create a record for AP SSID using AP interface MAC address

Step 2 above needs to make a call to

Code: Select all

esp_wifi_get_mac(ESP_IF_WIFI_AP, mac)
, which returns ESP_ERR_WIFI_NOT_INIT. I don't want to initialize the WiFi at this point; that will require de-initializing it right away.

Is there a way to get the MAC address without initializing the WiFi?

Also I'd like to hear some other strategy for generating unique (per device) AP SSIDs, if someone can suggest one.

Thanks

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Get AP MAC address wihout initializing WiFi

Postby chegewara » Sun Apr 17, 2022 6:55 am

esp_efuse_mac_get_custom(macAddr);

rtborg
Posts: 67
Joined: Wed Oct 23, 2019 6:15 am

Re: Get AP MAC address wihout initializing WiFi

Postby rtborg » Sun Apr 17, 2022 7:53 am

I tried that, but it fails:

Code: Select all

    
    if (ESP_OK == esp_efuse_mac_get_custom(ap_mac))
        sprintf((char *)name, "GATEWAY-%02X%02X", ap_mac[4], ap_mac[5]);
    else
        sprintf((char *)name, "GATEWAY-%02X%02X", 0xde, 0xad);

Code: Select all

I (568) system_api: Base MAC address is not set
I (578) system_api: read default base MAC address from EFUSE

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Get AP MAC address wihout initializing WiFi

Postby chegewara » Sun Apr 17, 2022 7:59 am

Sorry, you need this, similar, API, but both should return the same value in your case:

Code: Select all

esp_efuse_mac_get_default
https://github.com/espressif/esp-idf/bl ... ple_main.c

PS you also have to read about MAC addresses on esp32, because you will get BASE, which is STA address if i remember correctly, and AP address is not the same, but can be very easy calculated, by adding 1 to last HEX

rtborg
Posts: 67
Joined: Wed Oct 23, 2019 6:15 am

Re: Get AP MAC address wihout initializing WiFi

Postby rtborg » Sun Apr 17, 2022 11:20 am

Thanks for your reply, that did the trick.

Who is online

Users browsing this forum: Baidu [Spider] and 89 guests