Skip to content

Commit 2ceab7c

Browse files
a-c-sreedhar-reddyme-no-dev
authored andcommitted
return macaddress (#2477)
* WiFi.macaddress() returns mac address * change description * return macaddress when WiFi mode is WIFI_MODE_NULL
1 parent 84e458a commit 2ceab7c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
ESP8266WiFiSTA.cpp - WiFi library for esp8266
2+
WiFiSTA.cpp - WiFi library for esp32
33
44
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
55
This file is part of the esp8266 core for Arduino environment.
@@ -416,7 +416,10 @@ IPAddress WiFiSTAClass::localIP()
416416
uint8_t* WiFiSTAClass::macAddress(uint8_t* mac)
417417
{
418418
if(WiFiGenericClass::getMode() != WIFI_MODE_NULL){
419-
esp_wifi_get_mac(WIFI_IF_STA, mac);
419+
esp_wifi_get_mac(WIFI_IF_STA, mac);
420+
}
421+
else{
422+
esp_read_mac(mac, ESP_MAC_WIFI_STA);
420423
}
421424
return mac;
422425
}
@@ -430,10 +433,11 @@ String WiFiSTAClass::macAddress(void)
430433
uint8_t mac[6];
431434
char macStr[18] = { 0 };
432435
if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){
433-
return String();
436+
esp_read_mac(mac, ESP_MAC_WIFI_STA);
437+
}
438+
else{
439+
esp_wifi_get_mac(WIFI_IF_STA, mac);
434440
}
435-
esp_wifi_get_mac(WIFI_IF_STA, mac);
436-
437441
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
438442
return String(macStr);
439443
}

0 commit comments

Comments
 (0)