Added get_mac_addr()

This commit is contained in:
2021-10-28 02:48:09 +02:00
parent e8aa8dbf57
commit 6eb911c8ea
2 changed files with 13 additions and 0 deletions

View File

@@ -847,6 +847,18 @@ tl::expected<wifi_ap_record_t, std::string> 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 {

View File

@@ -73,6 +73,7 @@ void delete_scan_result();
//! Util wrappers
using mac_or_error = tl::expected<mac_t, std::string>;
tl::expected<wifi_ap_record_t, std::string> 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();