8#if (ESP_IDF_VERSION_MAJOR >= 5 && ESP_IDF_VERSION_MINOR >= 1)
9#include <esp_eap_client.h>
19#include <user_interface.h>
34#ifdef USE_CAPTIVE_PORTAL
44static const char *
const TAG =
"wifi";
235static const LogString *retry_phase_to_log_string(
WiFiRetryPhase phase) {
238 return LOG_STR(
"INITIAL_CONNECT");
239#ifdef USE_WIFI_FAST_CONNECT
241 return LOG_STR(
"FAST_CONNECT_CYCLING");
244 return LOG_STR(
"EXPLICIT_HIDDEN");
246 return LOG_STR(
"SCAN_CONNECTING");
248 return LOG_STR(
"RETRY_HIDDEN");
250 return LOG_STR(
"RESTARTING");
252 return LOG_STR(
"UNKNOWN");
259 return !this->
sta_.empty() && this->
sta_[0].get_hidden();
265 for (
size_t i = 0; i < this->
sta_.size(); i++) {
266 if (!this->
sta_[i].get_hidden()) {
267 return static_cast<int8_t
>(i);
278static constexpr uint8_t WIFI_RETRY_COUNT_PER_BSSID = 2;
282static constexpr uint8_t WIFI_RETRY_COUNT_PER_SSID = 1;
286static constexpr uint8_t WIFI_RETRY_COUNT_PER_AP = 1;
290static constexpr uint32_t WIFI_COOLDOWN_DURATION_MS = 500;
295static constexpr uint32_t WIFI_COOLDOWN_WITH_AP_ACTIVE_MS = 30000;
300static constexpr uint32_t WIFI_SCAN_TIMEOUT_MS = 31000;
310static constexpr uint32_t WIFI_CONNECT_TIMEOUT_MS = 46000;
312static constexpr uint8_t get_max_retries_for_phase(
WiFiRetryPhase phase) {
315#ifdef USE_WIFI_FAST_CONNECT
319 return WIFI_RETRY_COUNT_PER_AP;
322 return WIFI_RETRY_COUNT_PER_SSID;
325 return WIFI_RETRY_COUNT_PER_BSSID;
328 return WIFI_RETRY_COUNT_PER_SSID;
330 return WIFI_RETRY_COUNT_PER_BSSID;
334static void apply_scan_result_to_params(WiFiAP ¶ms,
const WiFiScanResult &scan) {
335 params.set_hidden(
false);
336 params.set_ssid(scan.get_ssid());
337 params.set_bssid(scan.get_bssid());
338 params.set_channel(scan.get_channel());
353 for (
const auto &conf : this->
sta_) {
354 if (conf.get_ssid() == ssid && conf.get_hidden()) {
361 if (scan.get_ssid() == ssid) {
388 for (
size_t i = start_index + 1; i < this->
sta_.size(); i++) {
389 const auto &sta = this->
sta_[i];
394 if (!include_explicit_hidden && sta.get_hidden()) {
396 if (first_non_hidden_idx < 0 ||
static_cast<int8_t
>(i) < first_non_hidden_idx) {
397 ESP_LOGD(TAG,
"Skipping " LOG_SECRET(
"'%s'")
" (explicit hidden, already tried)", sta.get_ssid().c_str());
405 ESP_LOGD(TAG,
"Hidden candidate " LOG_SECRET(
"'%s'")
" at index %d", sta.get_ssid().c_str(),
static_cast<int>(i));
406 return static_cast<int8_t
>(i);
408 ESP_LOGD(TAG,
"Skipping hidden retry for visible network " LOG_SECRET(
"'%s'"), sta.get_ssid().c_str());
417 if (!this->
sta_.empty() && this->sta_[0].get_hidden()) {
418 ESP_LOGI(TAG,
"Starting with explicit hidden network (highest priority)");
428#if defined(USE_ESP32) && defined(USE_WIFI_WPA2_EAP) && ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
429static const char *eap_phase2_to_str(esp_eap_ttls_phase2_types
type) {
431 case ESP_EAP_TTLS_PHASE2_PAP:
433 case ESP_EAP_TTLS_PHASE2_CHAP:
435 case ESP_EAP_TTLS_PHASE2_MSCHAP:
437 case ESP_EAP_TTLS_PHASE2_MSCHAPV2:
439 case ESP_EAP_TTLS_PHASE2_EAP:
452#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
457 ESP_LOGE(TAG,
"Failed semaphore");
475 ESP_LOGCONFIG(TAG,
"Starting");
481#ifdef USE_WIFI_FAST_CONNECT
487 ESP_LOGD(TAG,
"Loaded settings: %s", save.ssid);
491 sta.set_password(save.password);
498 ESP_LOGV(TAG,
"Setting Output Power Option failed");
501#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
505 if (semaphore_count > 0) {
515 ESP_LOGV(TAG,
"Setting Power Save Option failed");
519#ifdef USE_WIFI_FAST_CONNECT
524 if (loaded_fast_connect) {
525 ESP_LOGI(TAG,
"Starting fast_connect (saved) " LOG_SECRET(
"'%s'"), params.
get_ssid().c_str());
527 }
else if (!this->
sta_.empty() && !this->sta_[0].get_hidden()) {
529 ESP_LOGI(TAG,
"Starting fast_connect (config) " LOG_SECRET(
"'%s'"), this->
sta_[0].get_ssid().c_str());
542 }
else if (this->
has_ap()) {
545 ESP_LOGV(TAG,
"Setting Output Power Option failed");
547#ifdef USE_CAPTIVE_PORTAL
566 ESP_LOGW(TAG,
"Restarting adapter");
601 uint32_t cooldown_duration = portal_active ? WIFI_COOLDOWN_WITH_AP_ACTIVE_MS : WIFI_COOLDOWN_DURATION_MS;
624 ESP_LOGW(TAG,
"Connection lost; reconnecting");
656 ESP_LOGI(TAG,
"Starting fallback AP");
658#ifdef USE_CAPTIVE_PORTAL
679 ESP_LOGE(TAG,
"Can't connect; rebooting");
685#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
693 ESP_LOGV(TAG,
"Switching to high-performance mode (%" PRIu32
" active %s)", (uint32_t) semaphore_count,
694 semaphore_count == 1 ?
"request" :
"requests");
701 ESP_LOGV(TAG,
"Restoring power save mode to configured setting");
716#ifdef USE_WIFI_11KV_SUPPORT
750 if (name.length() > 32) {
753 name.erase(25, name.length() - 32);
762 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
766 " AP Password: '%s'\n"
768 this->
ap_.
get_ssid().c_str(), this->ap_.get_password().c_str(), this->wifi_soft_ap_ip().str_to(ip_buf));
770#ifdef USE_WIFI_MANUAL_IP
772 if (manual_ip.has_value()) {
773 char static_ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
774 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
775 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
777 " AP Static IP: '%s'\n"
778 " AP Gateway: '%s'\n"
780 manual_ip->static_ip.str_to(static_ip_buf), manual_ip->gateway.str_to(gateway_buf),
781 manual_ip->subnet.str_to(subnet_buf));
819 if (config ==
nullptr) {
820 ESP_LOGE(TAG,
"No valid network config (selected_sta_index_=%d, sta_.size()=%zu)",
830#ifdef USE_WIFI_FAST_CONNECT
848 apply_scan_result_to_params(params, this->
scan_result_[0]);
862 return config ? *config :
WiFiAP{};
866 strncpy(save.ssid, ssid.c_str(),
sizeof(save.ssid) - 1);
867 strncpy(save.password, password.c_str(),
sizeof(save.password) - 1);
874 sta.set_password(password);
884 ESP_LOGD(TAG,
"Exiting cooldown early due to new WiFi credentials");
900 "Connecting to " LOG_SECRET(
"'%s'")
" " LOG_SECRET(
"(%s)")
" (priority %d, attempt %u/%u in phase %s)...",
904#ifdef ESPHOME_LOG_HAS_VERBOSE
906 "Connection Params:\n"
910 ESP_LOGV(TAG,
" BSSID: %s", bssid_s);
912 ESP_LOGV(TAG,
" BSSID: Not Set");
915#ifdef USE_WIFI_WPA2_EAP
916 if (ap.
get_eap().has_value()) {
921 " WPA2 Enterprise authentication configured:\n"
922 " Identity: " LOG_SECRET(
"'%s'")
"\n"
923 " Username: " LOG_SECRET(
"'%s'")
"\n"
924 " Password: " LOG_SECRET(
"'%s'"),
927#if defined(USE_ESP32) && defined(USE_WIFI_WPA2_EAP) && ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
928 ESP_LOGV(TAG,
" TTLS Phase 2: " LOG_SECRET(
"'%s'"), eap_phase2_to_str(eap_config.
ttls_phase_2));
930 bool ca_cert_present = eap_config.
ca_cert !=
nullptr && strlen(eap_config.
ca_cert);
937 ca_cert_present ?
"present" :
"not present", client_cert_present ?
"present" :
"not present",
938 client_key_present ?
"present" :
"not present");
941 ESP_LOGV(TAG,
" Password: " LOG_SECRET(
"'%s'"), ap.
get_password().c_str());
942#ifdef USE_WIFI_WPA2_EAP
948 ESP_LOGV(TAG,
" Channel not set");
950#ifdef USE_WIFI_MANUAL_IP
953 char static_ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
954 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
955 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
956 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
957 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
958 ESP_LOGV(TAG,
" Manual IP: Static IP=%s Gateway=%s Subnet=%s DNS1=%s DNS2=%s",
m.static_ip.str_to(static_ip_buf),
959 m.gateway.str_to(gateway_buf),
m.subnet.str_to(subnet_buf),
m.dns1.str_to(dns1_buf),
960 m.dns2.str_to(dns2_buf));
964 ESP_LOGV(TAG,
" Using DHCP IP");
966 ESP_LOGV(TAG,
" Hidden: %s", YESNO(ap.
get_hidden()));
976 ESP_LOGE(TAG,
"wifi_sta_connect_ failed");
996 return LOG_STR(
"\033[0;32m"
1002 }
else if (rssi >= -65) {
1003 return LOG_STR(
"\033[0;33m"
1010 }
else if (rssi >= -85) {
1011 return LOG_STR(
"\033[0;33m"
1019 return LOG_STR(
"\033[0;31m"
1031 char bssid_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
1034 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
1037 ESP_LOGCONFIG(TAG,
" IP Address: %s", ip.str_to(ip_buf));
1042 char ssid_buf[SSID_BUFFER_SIZE];
1043 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
1044 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
1045 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
1046 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
1049 " SSID: " LOG_SECRET(
"'%s'")
"\n"
1050 " BSSID: " LOG_SECRET(
"%s")
"\n"
1052 " Signal strength: %d dB %s\n"
1053 " Channel: %" PRId32
"\n"
1062#ifdef ESPHOME_LOG_HAS_VERBOSE
1064 ESP_LOGV(TAG,
" Priority: %d", this->
get_sta_priority(config->get_bssid()));
1067#ifdef USE_WIFI_11KV_SUPPORT
1071 this->
btm_ ?
"enabled" :
"disabled", this->
rrm_ ?
"enabled" :
"disabled");
1079 ESP_LOGD(TAG,
"Enabling");
1088 ESP_LOGD(TAG,
"Disabling");
1098 ESP_LOGD(TAG,
"Starting scan");
1157template<
typename VectorType>
static void insertion_sort_scan_results(VectorType &results) {
1158 const size_t size = results.size();
1159 for (
size_t i = 1; i < size; i++) {
1161 WiFiScanResult key = results[i];
1166 while (j >= 0 && wifi_scan_result_is_better(key, results[j])) {
1167 results[j + 1] = results[j];
1170 results[j + 1] = key;
1186#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
1188 ESP_LOGI(TAG,
"- '%s' %s" LOG_SECRET(
"(%s) ")
"%s Ch:%2u %3ddB P:%d", res.
get_ssid().c_str(),
1189 res.
get_is_hidden() ? LOG_STR_LITERAL(
"(HIDDEN) ") : LOG_STR_LITERAL(
""), bssid_s,
1192 ESP_LOGI(TAG,
"- '%s' %s" LOG_SECRET(
"(%s) ")
"%s", res.
get_ssid().c_str(),
1193 res.
get_is_hidden() ? LOG_STR_LITERAL(
"(HIDDEN) ") : LOG_STR_LITERAL(
""), bssid_s,
1198#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
1200__attribute__((noinline))
static void log_scan_result_non_matching(
const WiFiScanResult &res) {
1202 auto bssid = res.get_bssid();
1205 ESP_LOGV(TAG,
"- " LOG_SECRET(
"'%s'")
" " LOG_SECRET(
"(%s) ")
"%s", res.get_ssid().c_str(), bssid_s,
1213 ESP_LOGE(TAG,
"Scan timeout");
1222 ESP_LOGW(TAG,
"No networks found");
1227 ESP_LOGD(TAG,
"Found networks:");
1229 for (
auto &ap : this->
sta_) {
1230 if (res.matches(ap)) {
1231 res.set_matches(
true);
1233 const bssid_t &bssid = res.get_bssid();
1244 insertion_sort_scan_results(this->scan_result_);
1246 size_t non_matching_count = 0;
1247 for (
auto &res : this->scan_result_) {
1248 if (res.get_matches()) {
1249 log_scan_result(res);
1251#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
1252 log_scan_result_non_matching(res);
1254 non_matching_count++;
1258 if (non_matching_count > 0) {
1259 ESP_LOGD(TAG,
"- %zu non-matching (VERBOSE to show)", non_matching_count);
1267 bool found_match =
false;
1269 for (
size_t i = 0; i < this->
sta_.size(); i++) {
1270 if (scan_res.
matches(this->sta_[i])) {
1281 ESP_LOGW(TAG,
"No matching network found");
1303 char mac_s[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
1310 ESP_LOGCONFIG(TAG,
" Disabled");
1322 char ssid_buf[SSID_BUFFER_SIZE];
1324 ESP_LOGW(TAG,
"Connection incomplete");
1329 ESP_LOGI(TAG,
"Connected");
1335 ESP_LOGW(TAG, LOG_SECRET(
"'%s'")
" should be marked hidden", config->get_ssid().c_str());
1341#ifdef USE_CAPTIVE_PORTAL
1346 ESP_LOGD(TAG,
"Disabling AP");
1365 ESP_LOGD(TAG,
"Roam successful");
1380#ifdef USE_WIFI_FAST_CONNECT
1390 ESP_LOGW(TAG,
"Connection timeout, aborting connection attempt");
1397 ESP_LOGW(TAG,
"Connecting to network failed (callback)");
1407 ESP_LOGW(TAG,
"Network no longer found");
1413 ESP_LOGW(TAG,
"Connecting to network failed");
1418 ESP_LOGW(TAG,
"Unknown connection status %d", (
int)
status);
1431#ifdef USE_WIFI_FAST_CONNECT
1440 if (!this->
sta_.empty() && this->sta_[0].get_hidden()) {
1448 if (this->
num_retried_ + 1 < WIFI_RETRY_COUNT_PER_SSID) {
1455 if (next_index < this->
sta_.size() && this->sta_[next_index].get_hidden()) {
1471 if (this->
scan_result_.empty() || !this->scan_result_[0].get_matches()) {
1475 if (this->
num_retried_ + 1 < WIFI_RETRY_COUNT_PER_BSSID) {
1494 if (this->
num_retried_ + 1 < WIFI_RETRY_COUNT_PER_SSID) {
1559 if (old_phase == new_phase) {
1563 ESP_LOGD(TAG,
"Retry phase: %s → %s", LOG_STR_ARG(retry_phase_to_log_string(old_phase)),
1564 LOG_STR_ARG(retry_phase_to_log_string(new_phase)));
1570 switch (new_phase) {
1571#ifdef USE_WIFI_FAST_CONNECT
1586#ifdef USE_WIFI_FAST_CONNECT
1588 ESP_LOGI(TAG,
"Fast connect exhausted, falling back to scan");
1616 ESP_LOGD(TAG,
"All SSIDs visible or already tried, skipping hidden mode");
1669 if (first_priority != std::numeric_limits<int8_t>::min()) {
1674 if (pri.priority != first_priority) {
1680 ESP_LOGD(TAG,
"Clearing BSSID priorities (all at minimum)");
1711 failed_bssid = config->get_bssid();
1719 const std::string *ssid =
nullptr;
1723 ssid = &config->get_ssid();
1728 uint8_t max_retries = get_max_retries_for_phase(this->
retry_phase_);
1729 bool is_last_attempt = (this->
num_retried_ + 1 >= max_retries);
1733 int8_t new_priority = old_priority;
1735 if (is_last_attempt) {
1738 (old_priority > std::numeric_limits<int8_t>::min()) ? (old_priority - 1) : std::numeric_limits<int8_t>::min();
1743 ESP_LOGD(TAG,
"Failed " LOG_SECRET(
"'%s'")
" " LOG_SECRET(
"(%s)")
", priority %d → %d",
1744 ssid !=
nullptr ? ssid->c_str() :
"", bssid_s, old_priority, new_priority);
1765#ifdef USE_WIFI_FAST_CONNECT
1770 ESP_LOGD(TAG,
"Next AP in %s", LOG_STR_ARG(retry_phase_to_log_string(this->
retry_phase_)));
1779 if (next_index < this->
sta_.size() && this->sta_[next_index].get_hidden()) {
1782 ESP_LOGD(TAG,
"Next explicit hidden network at index %d",
static_cast<int>(next_index));
1794 if (next_index != -1) {
1814 ESP_LOGD(TAG,
"Retry attempt %u/%u in phase %s", this->
num_retried_ + 1,
1846 if (next_phase == current_phase) {
1881#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
1889#ifdef USE_CAPTIVE_PORTAL
1903#if defined(USE_ESP32) && defined(USE_WIFI_RUNTIME_POWER_SAVE)
1935#ifdef USE_WIFI_FAST_CONNECT
1941 if (fast_connect_save.ap_index < 0 ||
static_cast<size_t>(fast_connect_save.ap_index) >= this->sta_.size()) {
1942 ESP_LOGW(TAG,
"AP index out of bounds");
1950 params = this->
sta_[fast_connect_save.ap_index];
1954 std::copy(fast_connect_save.bssid, fast_connect_save.bssid + 6, bssid.begin());
1960 ESP_LOGD(TAG,
"Loaded fast_connect settings");
1976 if (this->
fast_connect_pref_.
load(&previous_save) && memcmp(previous_save.bssid, bssid.data(), 6) == 0 &&
1977 previous_save.channel == channel && previous_save.ap_index == ap_index) {
1982 memcpy(fast_connect_save.bssid, bssid.data(), 6);
1983 fast_connect_save.channel = channel;
1984 fast_connect_save.ap_index = ap_index;
1988 ESP_LOGD(TAG,
"Saved fast_connect settings");
1996#ifdef USE_WIFI_WPA2_EAP
2001#ifdef USE_WIFI_MANUAL_IP
2009#ifdef USE_WIFI_WPA2_EAP
2014#ifdef USE_WIFI_MANUAL_IP
2024 ssid_(std::move(ssid)),
2025 with_auth_(with_auth),
2026 is_hidden_(is_hidden) {}
2033 }
else if (!config.
get_ssid().empty()) {
2035 if (config.
get_ssid() != this->ssid_)
2044#ifdef USE_WIFI_WPA2_EAP
2096 if (selected ==
nullptr || selected->
get_hidden()) {
2107 ESP_LOGV(TAG,
"Roam check skipped, signal good (%d dBm, attempt %u/%u)", rssi, this->
roaming_attempts_,
2123 int8_t current_rssi = this->
wifi_rssi();
2125 if (current_rssi == WIFI_RSSI_DISCONNECTED) {
2130 char ssid_buf[SSID_BUFFER_SIZE];
2136 char bssid_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
2140 if (current_ssid != result.get_ssid() || result.get_bssid() == current_bssid)
2143#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
2145 ESP_LOGV(TAG,
"Roam candidate %s %d dBm", bssid_buf, result.get_rssi());
2156 int8_t improvement = (best ==
nullptr) ? 0 : best->
get_rssi() - current_rssi;
2165 ESP_LOGI(TAG,
"Roaming to %s (%+d dB)", bssid_buf, improvement);
2167 WiFiAP roam_params = *selected;
2168 apply_scan_result_to_params(roam_params, *best);
bool is_name_add_mac_suffix_enabled() const
const std::string & get_name() const
Get the name of this Application set by pre_setup().
constexpr uint32_t get_config_version_hash()
Get the config hash extended with ESPHome version.
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
virtual bool sync()=0
Commit pending writes to flash.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
StringRef is a reference to a string owned by something else.
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
value_type const & value() const
uint8_t get_channel() const
const std::string & get_ssid() const
void set_ssid(const std::string &ssid)
const optional< EAPAuth > & get_eap() const
const std::string & get_password() const
void set_bssid(const bssid_t &bssid)
void set_channel(uint8_t channel)
optional< ManualIP > manual_ip_
void set_eap(optional< EAPAuth > eap_auth)
void set_password(const std::string &password)
void set_manual_ip(optional< ManualIP > manual_ip)
const optional< ManualIP > & get_manual_ip() const
void set_hidden(bool hidden)
const bssid_t & get_bssid() const
This component is responsible for managing the ESP WiFi interface.
bool is_captive_portal_active_()
bool error_from_callback_
void add_sta(const WiFiAP &ap)
bool load_fast_connect_settings_(WiFiAP ¶ms)
bool wifi_apply_power_save_()
void set_ap(const WiFiAP &ap)
Setup an Access Point that should be created if no connection to a station can be made.
bool request_high_performance()
Request high-performance mode (no power saving) for improved WiFi latency.
ESPPreferenceObject pref_
void set_sta(const WiFiAP &ap)
WiFiPowerSaveMode power_save_
bool has_sta_priority(const bssid_t &bssid)
const WiFiAP * get_selected_sta_() const
uint32_t roaming_last_check_
int8_t get_sta_priority(const bssid_t bssid)
void log_and_adjust_priority_for_failed_connect_()
Log failed connection and decrease BSSID priority to avoid repeated attempts.
void init_sta(size_t count)
void save_wifi_sta(const std::string &ssid, const std::string &password)
WiFiComponentState state_
wifi_scan_vector_t< WiFiScanResult > scan_result_
bool skip_cooldown_next_cycle_
WiFiPowerSaveMode configured_power_save_
void set_sta_priority(const bssid_t bssid, int8_t priority)
void print_connect_params_()
void loop() override
Reconnect WiFi if required.
void start_connecting(const WiFiAP &ap)
void advance_to_next_target_or_increment_retry_()
Advance to next target (AP/SSID) within current phase, or increment retry counter Called when staying...
void check_roaming_(uint32_t now)
static constexpr uint32_t ROAMING_CHECK_INTERVAL
RoamingState roaming_state_
void check_scanning_finished()
void process_roaming_scan_()
SemaphoreHandle_t high_performance_semaphore_
network::IPAddress get_dns_address(int num)
WiFiComponent()
Construct a WiFiComponent.
std::vector< WiFiSTAPriority > sta_priorities_
int8_t selected_sta_index_
static constexpr int8_t ROAMING_GOOD_RSSI
void save_fast_connect_settings_()
bool wifi_start_ap_(const WiFiAP &ap)
int32_t get_wifi_channel()
const char * wifi_ssid_to(std::span< char, SSID_BUFFER_SIZE > buffer)
Write SSID to buffer without heap allocation.
network::IPAddress wifi_subnet_mask_()
static constexpr uint8_t ROAMING_MAX_ATTEMPTS
network::IPAddress wifi_soft_ap_ip()
void set_passive_scan(bool passive)
uint8_t roaming_attempts_
network::IPAddress wifi_gateway_ip_()
void set_power_save_mode(WiFiPowerSaveMode power_save)
bool is_ap_active() const
int8_t find_next_hidden_sta_(int8_t start_index)
Find next SSID that wasn't in scan results (might be hidden) Returns index of next potentially hidden...
Trigger * connect_trigger_
ESPPreferenceObject fast_connect_pref_
void clear_priorities_if_all_min_()
Clear BSSID priority tracking if all priorities are at minimum (saves memory)
WiFiRetryPhase determine_next_phase_()
Determine next retry phase based on current state and failure conditions.
network::IPAddress wifi_dns_ip_(int num)
float get_loop_priority() const override
bool wifi_apply_hostname_()
bool wifi_sta_pre_setup_()
network::IPAddresses get_ip_addresses()
static constexpr int8_t ROAMING_MIN_IMPROVEMENT
Trigger * disconnect_trigger_
float get_setup_priority() const override
WIFI setup_priority.
bool is_esp32_improv_active_()
FixedVector< WiFiAP > sta_
int8_t find_first_non_hidden_index_() const
Find the index of the first non-hidden network Returns where EXPLICIT_HIDDEN phase would have stopped...
void release_scan_results_()
Free scan results memory unless a component needs them.
bool ssid_was_seen_in_scan_(const std::string &ssid) const
Check if an SSID was seen in the most recent scan results Used to skip hidden mode for SSIDs we know ...
bool needs_scan_results_() const
Check if we need valid scan results for the current phase but don't have any Returns true if the phas...
WiFiRetryPhase retry_phase_
bool transition_to_phase_(WiFiRetryPhase new_phase)
Transition to a new retry phase with logging Returns true if a scan was started (caller should wait),...
WiFiAP build_params_for_current_phase_()
bool is_high_performance_mode_
void dump_config() override
void clear_roaming_state_()
bool release_high_performance()
Release a high-performance mode request.
RetryHiddenMode retry_hidden_mode_
bool wifi_apply_output_power_(float output_power)
const char * get_use_address() const
WiFiSTAConnectStatus wifi_sta_connect_status_()
bool wifi_sta_connect_(const WiFiAP &ap)
bool went_through_explicit_hidden_phase_() const
Check if we went through EXPLICIT_HIDDEN phase (first network is marked hidden) Used in RETRY_HIDDEN ...
bool wifi_mode_(optional< bool > sta, optional< bool > ap)
void set_reboot_timeout(uint32_t reboot_timeout)
bool can_proceed() override
network::IPAddresses wifi_sta_ip_addresses()
void check_connecting_finished(uint32_t now)
void start_initial_connection_()
Start initial connection - either scan or connect directly to hidden networks.
bool wifi_scan_start_(bool passive)
bool handled_connected_state_
void setup() override
Setup WiFi interface.
void clear_all_bssid_priorities_()
Clear all BSSID priority penalties after successful connection (stale after disconnect)
void set_use_address(const char *use_address)
bool post_connect_roaming_
const std::string & get_ssid() const
int8_t get_priority() const
uint8_t get_channel() const
bool get_with_auth() const
const bssid_t & get_bssid() const
WiFiScanResult(const bssid_t &bssid, std::string ssid, uint8_t channel, int8_t rssi, bool with_auth, bool is_hidden)
bool matches(const WiFiAP &config) const
void set_matches(bool matches)
bool get_is_hidden() const
bool operator==(const WiFiScanResult &rhs) const
struct @65::@66 __attribute__
CaptivePortal * global_captive_portal
ESP32ImprovComponent * global_improv_component
std::array< IPAddress, 5 > IPAddresses
std::array< uint8_t, 6 > bssid_t
const LogString * get_signal_bars(int8_t rssi)
@ BLIND_RETRY
Blind retry mode: scanning disabled (captive portal/improv active), try ALL configured networks seque...
@ SCAN_BASED
Normal mode: scan completed, only try networks NOT visible in scan results (truly hidden networks tha...
@ ERROR_NETWORK_NOT_FOUND
WiFiRetryPhase
Tracks the current retry strategy/phase for WiFi connection attempts.
@ RETRY_HIDDEN
Retry networks not found in scan (might be hidden)
@ RESTARTING_ADAPTER
Restarting WiFi adapter to clear stuck state.
@ INITIAL_CONNECT
Initial connection attempt (varies based on fast_connect setting)
@ EXPLICIT_HIDDEN
Explicitly hidden networks (user marked as hidden, try before scanning)
@ FAST_CONNECT_CYCLING_APS
Fast connect mode: cycling through configured APs (config-only, no scan)
@ SCAN_CONNECTING
Scan-based: connecting to best AP from scan results.
WiFiComponent * global_wifi_component
@ SCANNING
Scanning for better AP.
@ CONNECTING
Attempting to connect to better AP found in scan.
@ IDLE
Not roaming, waiting for next check interval.
@ RECONNECTING
Roam connection failed, reconnecting to any available AP.
@ WIFI_COMPONENT_STATE_DISABLED
WiFi is disabled.
@ WIFI_COMPONENT_STATE_AP
WiFi is in AP-only mode and internal AP is already enabled.
@ WIFI_COMPONENT_STATE_STA_CONNECTING
WiFi is in STA(+AP) mode and currently connecting to an AP.
@ WIFI_COMPONENT_STATE_OFF
Nothing has been initialized yet.
@ WIFI_COMPONENT_STATE_STA_SCANNING
WiFi is in STA-only mode and currently scanning for APs.
@ WIFI_COMPONENT_STATE_COOLDOWN
WiFi is in cooldown mode because something went wrong, scanning will begin after a short period of ti...
@ WIFI_COMPONENT_STATE_STA_CONNECTED
WiFi is in STA(+AP) mode and successfully connected.
ESPPreferences * global_preferences
void IRAM_ATTR HOT yield()
const char * get_mac_address_pretty_into_buffer(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf)
Get the device MAC address into the given buffer, in colon-separated uppercase hex notation.
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
char * format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase, colon separators)
esp_eap_ttls_phase2_types ttls_phase_2
Struct for setting static IPs in WiFiComponent.