Skip to content

Commit 8f79cde

Browse files
committed
Get the correct interface MAC address for mDND Workstation service
1 parent d5d59d3 commit 8f79cde

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: libraries/ESPmDNS/src/ESPmDNS.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ License (MIT license):
4141
#include "ESPmDNS.h"
4242
#include <functional>
4343
#include "esp_mac.h"
44+
#include "soc/soc_caps.h"
4445

4546
// Add quotes around defined value
4647
#ifdef __IN_ECLIPSE__
@@ -132,7 +133,25 @@ void MDNSResponder::disableArduino(){
132133
void MDNSResponder::enableWorkstation(esp_interface_t interface){
133134
char winstance[21+_hostname.length()];
134135
uint8_t mac[6];
135-
esp_base_mac_addr_get(mac);
136+
137+
esp_mac_type_t mtype = ESP_MAC_ETH;
138+
#if SOC_WIFI_SUPPORTED
139+
switch(interface){
140+
case ESP_IF_WIFI_STA:
141+
mtype = ESP_MAC_WIFI_STA;
142+
break;
143+
case ESP_IF_WIFI_AP:
144+
mtype = ESP_MAC_WIFI_SOFTAP;
145+
break;
146+
default:
147+
break;
148+
}
149+
#endif
150+
if(esp_read_mac(mac, mtype) != ESP_OK){
151+
log_e("Failed to read the MAC address");
152+
return;
153+
}
154+
136155
sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
137156

138157
if(mdns_service_add(NULL, "_workstation", "_tcp", 9, NULL, 0)) {

0 commit comments

Comments
 (0)