diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d67401..c876f0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ set(dependencies cpputils espchrono espcpputils - fmt ) idf_component_register( diff --git a/Kconfig.projbuild b/Kconfig.projbuild index e99acfc..300afec 100644 --- a/Kconfig.projbuild +++ b/Kconfig.projbuild @@ -44,4 +44,9 @@ config WIFI_LOG_WORKAROUND bool "Enable disabled-log bug workaround (by enabling certain log statements)" default false +config WIFI_STA_CONFIG_COUNT + int "Maximum number of STA configurations" + default 5 + range 1 10 + endmenu diff --git a/src/espwifistack.cpp b/src/espwifistack.cpp index c2ef19a..12947df 100644 --- a/src/espwifistack.cpp +++ b/src/espwifistack.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include // esp-idf includes #include @@ -44,7 +46,6 @@ #endif // 3rdparty lib includes -#include #include #include #include @@ -817,7 +818,7 @@ void update(const config &config) std::string sta_error_t::toString() const { - return fmt::format("{} WIFI_STA_DISCONNECTED ssid=\"{}\" bssid={} reason={}({})", + return std::format("{} WIFI_STA_DISCONNECTED ssid=\"{}\" bssid={} reason={}({})", timestamp.time_since_epoch().count(), ssid, wifi_stack::toString(bssid), std::to_underlying(reason), wifi_stack::toString(reason)); @@ -880,7 +881,7 @@ std::expected begin_scan(const sta_config &sta_config) return std::unexpected("invalid scan settings (not active nor passive)!"); if (const auto result = esp_wifi_scan_start(&scan_config, false) != ESP_OK) - return std::unexpected(fmt::format("esp_wifi_scan_start() failed with: {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_wifi_scan_start() failed with: {}", esp_err_to_name(result))); scanStarted = espchrono::millis_clock::now(); @@ -936,7 +937,7 @@ std::expected get_sta_ap_info() else { ESP_LOGW(TAG, "esp_wifi_sta_get_ap_info() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_wifi_sta_get_ap_info() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_wifi_sta_get_ap_info() failed with {}", esp_err_to_name(result))); } } @@ -948,7 +949,7 @@ mac_or_error get_mac_addr(wifi_interface_t ifx) else { ESP_LOGW(TAG, "esp_wifi_get_mac() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_wifi_get_mac() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_wifi_get_mac() failed with {}", esp_err_to_name(result))); } } @@ -961,7 +962,7 @@ mac_or_error get_default_mac_addr() else { //ESP_LOGE(TAG, "esp_efuse_mac_get_default() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_efuse_mac_get_default() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_efuse_mac_get_default() failed with {}", esp_err_to_name(result))); } }(); @@ -977,7 +978,7 @@ mac_or_error get_custom_mac_addr() else { //ESP_LOGE(TAG, "esp_efuse_mac_get_custom() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_efuse_mac_get_custom() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_efuse_mac_get_custom() failed with {}", esp_err_to_name(result))); } }(); @@ -992,7 +993,7 @@ mac_or_error get_base_mac_addr() else { ESP_LOGE(TAG, "esp_base_mac_addr_get() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_base_mac_addr_get() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_base_mac_addr_get() failed with {}", esp_err_to_name(result))); } } @@ -1003,7 +1004,7 @@ std::expected set_base_mac_addr(mac_t mac_addr) else { ESP_LOGE(TAG, "esp_base_mac_addr_set() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("esp_base_mac_addr_set() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_base_mac_addr_set() failed with {}", esp_err_to_name(result))); } } @@ -1015,7 +1016,7 @@ std::expected get_ip_info(esp_netif_t *esp_net else { ESP_LOGE(TAG, "esp_netif_get_ip_info() failed with %s", esp_err_to_name(result)); - return std::unexpected(fmt::format("tcpip_adapter_get_ip_info() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("tcpip_adapter_get_ip_info() failed with {}", esp_err_to_name(result))); } } @@ -1024,14 +1025,14 @@ std::expected get_hostname_for_interface(esp_inte if (const auto netif = esp_netifs[interf]) return get_hostname_for_interface(netif); else - return std::unexpected(fmt::format("netif for {} is invalid", std::to_underlying(interf))); + return std::unexpected(std::format("netif for {} is invalid", std::to_underlying(interf))); } std::expected get_hostname_for_interface(esp_netif_t *esp_netif) { const char *hostname{}; if (const auto result = esp_netif_get_hostname(esp_netif, &hostname)) - return std::unexpected(fmt::format("esp_netif_get_hostname() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_netif_get_hostname() failed with {}", esp_err_to_name(result))); if (!hostname) return std::unexpected("esp_netif_get_hostname() returned a nullptr string"); @@ -2128,7 +2129,7 @@ std::expected applyBaseMac(const mac_t &mac) return {}; else { - const auto msg = fmt::format("set_base_mac_addr() {} failed: {}", toString(mac), result.error()); + const auto msg = std::format("set_base_mac_addr() {} failed: {}", toString(mac), result.error()); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); return std::unexpected(msg); } @@ -2153,7 +2154,7 @@ std::expected expectedBaseMac(const config &config) return *mac; else { - const auto msg = fmt::format("no base mac fuse or override set and get_default_mac_addr() failed: {}", mac.error()); + const auto msg = std::format("no base mac fuse or override set and get_default_mac_addr() failed: {}", mac.error()); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); return std::unexpected(msg); } @@ -2820,7 +2821,7 @@ std::expected eth_begin(const config &config, const eth_confi if (const auto result = esp_eth_driver_install(ð_config, ð_handle); result != ESP_OK) { - auto msg = fmt::format("esp_eth_driver_install() failed with {}", esp_err_to_name(result)); + auto msg = std::format("esp_eth_driver_install() failed with {}", esp_err_to_name(result)); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); return std::unexpected(std::move(msg)); } @@ -2843,7 +2844,7 @@ std::expected eth_begin(const config &config, const eth_confi if (const auto result = esp_netif_attach(esp_netifs[ESP_IF_ETH], ptr); result != ESP_OK) { - auto msg = fmt::format("esp_netif_attach() failed with {}", esp_err_to_name(result)); + auto msg = std::format("esp_netif_attach() failed with {}", esp_err_to_name(result)); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); return std::unexpected(std::move(msg)); } @@ -2854,7 +2855,7 @@ std::expected eth_begin(const config &config, const eth_confi { if (const auto result = esp_eth_start(eth_handle); result != ESP_OK) { - auto msg = fmt::format("esp_eth_start() failed with {}", esp_err_to_name(result)); + auto msg = std::format("esp_eth_start() failed with {}", esp_err_to_name(result)); ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); return std::unexpected(std::move(msg)); } diff --git a/src/espwifistackconfig.h b/src/espwifistackconfig.h index 50d3cc1..e4f846f 100644 --- a/src/espwifistackconfig.h +++ b/src/espwifistackconfig.h @@ -163,7 +163,7 @@ struct dual_ant_config struct sta_config { std::string hostname; - std::array wifis; + std::array wifis; int8_t min_rssi = -90; bool long_range = false; wifi_bandwidth_t bandwidth = WIFI_BW_HT20; diff --git a/src/espwifiutils.cpp b/src/espwifiutils.cpp index d97b347..31fe9ac 100644 --- a/src/espwifiutils.cpp +++ b/src/espwifiutils.cpp @@ -4,13 +4,11 @@ #include #include #include +#include // esp-idf includes #include -// 3rdparty lib includes -#include - namespace wifi_stack { namespace { constexpr const char * const TAG = "WIFI_STACK"; @@ -68,9 +66,11 @@ std::string toString(wifi_auth_mode_t authMode) case WIFI_AUTH_WAPI_PSK: return "WAPI_PSK"; case WIFI_AUTH_OWE: return "OWE"; case WIFI_AUTH_MAX: return "MAX"; + case WIFI_AUTH_WPA3_ENT_192: return "WPA3_ENT_192"; + default:; } ESP_LOGW(TAG, "Unknown wifi_auth_mode_t(%i)", std::to_underlying(authMode)); - return fmt::format("Unknown wifi_auth_mode_t({})", std::to_underlying(authMode)); + return std::format("Unknown wifi_auth_mode_t({})", std::to_underlying(authMode)); } std::string toString(wifi_cipher_type_t cipherType) @@ -92,7 +92,7 @@ std::string toString(wifi_cipher_type_t cipherType) case WIFI_CIPHER_TYPE_UNKNOWN: return "UNKNOWN"; } ESP_LOGW(TAG, "Unknown wifi_cipher_type_t(%i)", std::to_underlying(cipherType)); - return fmt::format("Unknown wifi_cipher_type_t({})", std::to_underlying(cipherType)); + return std::format("Unknown wifi_cipher_type_t({})", std::to_underlying(cipherType)); } std::string toString(wifi_bandwidth_t bandwidth) @@ -101,9 +101,10 @@ std::string toString(wifi_bandwidth_t bandwidth) { case WIFI_BW_HT20: return "HT20"; case WIFI_BW_HT40: return "HT40"; + default:; } ESP_LOGW(TAG, "Unknown wifi_bandwidth_t(%i)", std::to_underlying(bandwidth)); - return fmt::format("Unknown wifi_bandwidth_t({})", std::to_underlying(bandwidth)); + return std::format("Unknown wifi_bandwidth_t({})", std::to_underlying(bandwidth)); } std::string toString(esp_interface_t interface) @@ -117,7 +118,7 @@ std::string toString(esp_interface_t interface) case ESP_IF_MAX: return "MAX"; } ESP_LOGW(TAG, "Unknown esp_interface_t(%i)", std::to_underlying(interface)); - return fmt::format("Unknown esp_interface_t({})", std::to_underlying(interface)); + return std::format("Unknown esp_interface_t({})", std::to_underlying(interface)); } std::string toString(esp_netif_dhcp_status_t status) @@ -130,7 +131,7 @@ std::string toString(esp_netif_dhcp_status_t status) case ESP_NETIF_DHCP_STATUS_MAX: return "STATUS_MAX"; } ESP_LOGW(TAG, "Unknown esp_netif_dhcp_status_t(%i)", std::to_underlying(status)); - return fmt::format("Unknown esp_netif_dhcp_status_t({})", std::to_underlying(status)); + return std::format("Unknown esp_netif_dhcp_status_t({})", std::to_underlying(status)); } const char * toString(wifi_err_reason_t reason) @@ -194,6 +195,7 @@ const char * toString(wifi_err_reason_t reason) case WIFI_REASON_ROAMING: return "ROAMING"; case WIFI_REASON_ASSOC_COMEBACK_TIME_TOO_LONG: return "ASSOC_COMEBACK_TIME_TOO_LONG"; case WIFI_REASON_SA_QUERY_TIMEOUT: return "SA_QUERY_TIMEOUT"; + default:; } ESP_LOGE(TAG, "unknown reason %" PRIu8, reason); @@ -225,12 +227,12 @@ template<> std::expected fromString(std::string_view &result[0], &result[1], &result[2], &result[3], &result[4], &result[5]) == 6) return result; - return std::unexpected(fmt::format("invalid format ({})", str)); + return std::unexpected(std::format("invalid format ({})", str)); } std::string toString(const mac_t &val) { - return fmt::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", + return std::format("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", val.at(0), val.at(1), val.at(2), val.at(3), val.at(4), val.at(5)); } @@ -279,7 +281,7 @@ template<> std::expected fromString(std std::string toString(ip_address_t val) { - return fmt::format("{}.{}.{}.{}", val[0], val[1], val[2], val[3]); + return std::format("{}.{}.{}.{}", val[0], val[1], val[2], val[3]); } std::string toString(const std::optional &val) @@ -330,9 +332,10 @@ std::string toString(ip_addr_t val) { case IPADDR_TYPE_V4: return toString(val.u_addr.ip4); case IPADDR_TYPE_V6: return toString(val.u_addr.ip6); + default:; } //ESP_LOGW(TAG, "Unknown ipv%hhu", val.type); - return fmt::format("Unknown ipv{}", val.type); + return std::format("Unknown ipv{}", val.type); } std::string toString(const esp_ip_addr_t &val) @@ -341,9 +344,10 @@ std::string toString(const esp_ip_addr_t &val) { case IPADDR_TYPE_V4: return toString(val.u_addr.ip4); case IPADDR_TYPE_V6: return toString(val.u_addr.ip6); + default:; } ESP_LOGW(TAG, "Unknown ipv%hhu", val.type); - return fmt::format("Unknown ipv{}", val.type); + return std::format("Unknown ipv{}", val.type); } } // namespace wifi_stack diff --git a/src/udpsender.cpp b/src/udpsender.cpp index 0a6d991..ab79a0e 100644 --- a/src/udpsender.cpp +++ b/src/udpsender.cpp @@ -2,6 +2,7 @@ // system #include +#include // esp-idf includes #include @@ -9,9 +10,6 @@ #include #include -// 3rdparty lib includes -#include - // local includes #include "espwifistack.h" @@ -42,7 +40,7 @@ std::expected UdpSender::send(esp_interface_t interf, uint16_ { const auto interfPtr = esp_netifs[interf]; if (!interfPtr) - return std::unexpected(fmt::format("esp_netifs[{}] is invalid", std::to_underlying(interf))); + return std::unexpected(std::format("esp_netifs[{}] is invalid", std::to_underlying(interf))); return send(interfPtr, port, buf); } @@ -54,7 +52,7 @@ std::expected UdpSender::send(esp_netif_t *interf, uint16_t p esp_netif_ip_info_t ip; if (const auto result = esp_netif_get_ip_info(interf, &ip); result != ESP_OK) - return std::unexpected(fmt::format("esp_netif_get_ip_info() failed with {}", esp_err_to_name(result))); + return std::unexpected(std::format("esp_netif_get_ip_info() failed with {}", esp_err_to_name(result))); return send(ip, port, buf); } @@ -77,9 +75,9 @@ std::expected UdpSender::send(const struct sockaddr_in &recip return std::unexpected("initializing failed, not ready to send"); if (const ssize_t sent = sendto(m_udp_server, buf.data(), buf.size(), 0, (const struct sockaddr*)&recipient, sizeof(recipient)); sent < 0) - return std::unexpected(fmt::format("send failed with {} (errno={})", sent, errno)); + return std::unexpected(std::format("send failed with {} (errno={})", sent, errno)); else if (sent != buf.size()) - return std::unexpected(fmt::format("sent bytes does not match, expected={}, sent={}", buf.size(), sent)); + return std::unexpected(std::format("sent bytes does not match, expected={}, sent={}", buf.size(), sent)); return {}; } @@ -90,9 +88,9 @@ std::expected UdpSender::send(const struct sockaddr_in6 &reci return std::unexpected("initializing failed, not ready to send"); if (const ssize_t sent = sendto(m_udp_server, buf.data(), buf.size(), 0, (const struct sockaddr*)&recipient, sizeof(recipient)); sent < 0) - return std::unexpected(fmt::format("send failed with {} (errno={})", sent, errno)); + return std::unexpected(std::format("send failed with {} (errno={})", sent, errno)); else if (sent != buf.size()) - return std::unexpected(fmt::format("sent bytes does not match, expected={}, sent={}", buf.size(), sent)); + return std::unexpected(std::format("sent bytes does not match, expected={}, sent={}", buf.size(), sent)); return {}; } @@ -122,7 +120,7 @@ std::expected UdpSender::send(ip_addr_t ip, uint16_t port, st return send(recipient, buf); } } - return std::unexpected(fmt::format("unsupported ip type {}", ip.type)); + return std::unexpected(std::format("unsupported ip type {}", ip.type)); } std::expected UdpSender::send(esp_ip_addr_t ip, uint16_t port, std::string_view buf) @@ -150,7 +148,7 @@ std::expected UdpSender::send(esp_ip_addr_t ip, uint16_t port return send(recipient, buf); } } - return std::unexpected(fmt::format("unsupported ip type {}", ip.type)); + return std::unexpected(std::format("unsupported ip type {}", ip.type)); } } // namespace wifi_stack