diff --git a/src/espwifistack.cpp b/src/espwifistack.cpp index 97987d5..6f3d067 100644 --- a/src/espwifistack.cpp +++ b/src/espwifistack.cpp @@ -847,6 +847,18 @@ tl::expected get_sta_ap_info() } } +mac_or_error get_mac_addr(wifi_interface_t ifx) +{ + wifi_stack::mac_t mac; + if (const auto result = esp_wifi_get_mac(ifx, std::begin(mac)); result == ESP_OK) + return mac; + else + { + ESP_LOGW(TAG, "esp_wifi_get_mac() failed with %s", esp_err_to_name(result)); + return tl::make_unexpected(fmt::format("esp_wifi_get_mac() failed with {}", esp_err_to_name(result))); + } +} + mac_or_error get_default_mac_addr() { static const mac_or_error cachedResult = []() -> mac_or_error { diff --git a/src/espwifistack.h b/src/espwifistack.h index 0b907fb..e4463d5 100644 --- a/src/espwifistack.h +++ b/src/espwifistack.h @@ -73,6 +73,7 @@ void delete_scan_result(); //! Util wrappers using mac_or_error = tl::expected; tl::expected get_sta_ap_info(); +mac_or_error get_mac_addr(wifi_interface_t ifx); mac_or_error get_default_mac_addr(); mac_or_error get_custom_mac_addr(); mac_or_error get_base_mac_addr();