From 6eb911c8eac2d50f5aa7e3cc35e4f691e59832a9 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 28 Oct 2021 02:48:09 +0200 Subject: [PATCH] Added get_mac_addr() --- src/espwifistack.cpp | 12 ++++++++++++ src/espwifistack.h | 1 + 2 files changed, 13 insertions(+) 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();