|
92 | 92 | #include "../../modules/usb-serial/usb_serial_service.h" |
93 | 93 | #endif // defined(USB_SERIAL_FEATURE) |
94 | 94 |
|
| 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 | + |
95 | 114 | // Get ESP current status |
96 | 115 | // output is JSON or plain text according parameter |
97 | 116 | //[ESP420]json=<no> |
@@ -584,7 +603,11 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) { |
584 | 603 | return; |
585 | 604 | } |
586 | 605 | // Disabled Mode |
| 606 | + #if defined(ARDUINO_ARCH_ESP32) |
| 607 | + tmpstr = getWifiMac(WIFI_IF_AP); |
| 608 | + #else |
587 | 609 | tmpstr = WiFi.softAPmacAddress(); |
| 610 | + #endif |
588 | 611 | if (!dispatchIdValue(json, "mac", tmpstr.c_str(), target, requestId, |
589 | 612 | false)) { |
590 | 613 | return; |
@@ -659,9 +682,13 @@ void ESP3DCommands::ESP420(int cmd_params_pos, ESP3DMessage* msg) { |
659 | 682 | false)) { |
660 | 683 | return; |
661 | 684 | } |
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, |
665 | 692 | false)) { |
666 | 693 | return; |
667 | 694 | } |
|
0 commit comments