From 2ceab7c2797f8dbfd4ec8f1829d0d3906ba05026 Mon Sep 17 00:00:00 2001 From: A C SREEDHAR REDDY Date: Sun, 3 Mar 2019 20:18:30 +0530 Subject: [PATCH] return macaddress (#2477) * WiFi.macaddress() returns mac address * change description * return macaddress when WiFi mode is WIFI_MODE_NULL --- libraries/WiFi/src/WiFiSTA.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index b76dea05..a3d40102 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -1,5 +1,5 @@ /* - ESP8266WiFiSTA.cpp - WiFi library for esp8266 + WiFiSTA.cpp - WiFi library for esp32 Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. @@ -416,7 +416,10 @@ IPAddress WiFiSTAClass::localIP() uint8_t* WiFiSTAClass::macAddress(uint8_t* mac) { if(WiFiGenericClass::getMode() != WIFI_MODE_NULL){ - esp_wifi_get_mac(WIFI_IF_STA, mac); + esp_wifi_get_mac(WIFI_IF_STA, mac); + } + else{ + esp_read_mac(mac, ESP_MAC_WIFI_STA); } return mac; } @@ -430,10 +433,11 @@ String WiFiSTAClass::macAddress(void) uint8_t mac[6]; char macStr[18] = { 0 }; if(WiFiGenericClass::getMode() == WIFI_MODE_NULL){ - return String(); + esp_read_mac(mac, ESP_MAC_WIFI_STA); + } + else{ + esp_wifi_get_mac(WIFI_IF_STA, mac); } - esp_wifi_get_mac(WIFI_IF_STA, mac); - sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return String(macStr); }