Skip to content

Commit 8c044d1

Browse files
committed
Fix Disabled Interface do not show Mac address on ESP32
1 parent 12f97eb commit 8c044d1

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

esp3d/src/core/commands/ESP420.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@
9292
#include "../../modules/usb-serial/usb_serial_service.h"
9393
#endif // defined(USB_SERIAL_FEATURE)
9494

95+
#if defined(ARDUINO_ARCH_ESP32)
96+
#include <esp_wifi.h>
97+
static String getWifiMac(wifi_interface_t iface) {
98+
uint8_t mac[6];
99+
esp_err_t err = esp_wifi_get_mac(iface, mac);
100+
if (err == ESP_OK) {
101+
102+
char buf[18];
103+
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
104+
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
105+
esp3d_log("MAC address for interface %d: %s", iface, buf);
106+
return String(buf);
107+
} else {
108+
esp3d_log("Error getting MAC address: %d , %s", err, esp_err_to_name(err));
109+
}
110+
return "00:00:00:00:00:00";
111+
}
112+
#endif // ARDUINO_ARCH_ESP8266
113+
95114
// Get ESP current status
96115
// output is JSON or plain text according parameter
97116
//[ESP420]json=<no>
@@ -584,7 +603,11 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) {
584603
return;
585604
}
586605
// Disabled Mode
606+
#if defined(ARDUINO_ARCH_ESP32)
607+
tmpstr = getWifiMac(WIFI_IF_AP);
608+
#else
587609
tmpstr = WiFi.softAPmacAddress();
610+
#endif
588611
if (!dispatchIdValue(json, "mac", tmpstr.c_str(), target, requestId,
589612
false)) {
590613
return;
@@ -659,9 +682,13 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) {
659682
false)) {
660683
return;
661684
}
662-
// Disabled Mode
663-
tmpstr = WiFi.macAddress();
664-
if (!dispatchIdValue(json, "mac", tmpstr.c_str(), target, requestId,
685+
686+
#if defined(ARDUINO_ARCH_ESP32)
687+
tmpstr = getWifiMac(WIFI_IF_STA);
688+
#else
689+
tmpstr = WiFi.macAddress();
690+
#endif // ARDUINO_ARCH_ESP32
691+
if (!dispatchIdValue(json, "mac", tmpstr.c_str(), target, requestId,
665692
false)) {
666693
return;
667694
}

0 commit comments

Comments
 (0)