12 #ifdef USE_ESP32_FRAMEWORK_ARDUINO 19 #include <ESP8266WiFi.h> 20 #include <ESP8266WiFiType.h> 22 #if defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE < VERSION_CODE(2, 4, 0) 24 #include <user_interface.h> 32 #include "cyw43_country.h" 33 #include "pico/cyw43_arch.h" 85 #ifdef USE_WIFI_WPA2_EAP 95 #endif // USE_WIFI_WPA2_EAP 101 void set_ssid(
const std::string &
ssid);
104 void set_password(
const std::string &
password);
105 #ifdef USE_WIFI_WPA2_EAP 107 #endif // USE_WIFI_WPA2_EAP 111 void set_hidden(
bool hidden);
112 const std::string &get_ssid()
const;
114 const std::string &get_password()
const;
115 #ifdef USE_WIFI_WPA2_EAP 117 #endif // USE_WIFI_WPA2_EAP 121 bool get_hidden()
const;
127 #ifdef USE_WIFI_WPA2_EAP 129 #endif // USE_WIFI_WPA2_EAP 140 bool matches(
const WiFiAP &config);
142 bool get_matches()
const;
143 void set_matches(
bool matches);
144 const bssid_t &get_bssid()
const;
145 const std::string &get_ssid()
const;
146 uint8_t get_channel()
const;
147 int8_t get_rssi()
const;
148 bool get_with_auth()
const;
149 bool get_is_hidden()
const;
156 bool matches_{
false};
163 float priority_{0.0f};
187 void set_sta(
const WiFiAP &ap);
188 void add_sta(
const WiFiAP &ap);
198 void set_ap(
const WiFiAP &ap);
201 void start_scanning();
202 void check_scanning_finished();
203 void start_connecting(
const WiFiAP &ap,
bool two);
204 void set_fast_connect(
bool fast_connect);
207 void check_connecting_finished();
209 void retry_connect();
211 bool can_proceed()
override;
213 void set_reboot_timeout(uint32_t reboot_timeout);
220 void save_wifi_sta(
const std::string &
ssid,
const std::string &
password);
224 void setup()
override;
225 void dump_config()
override;
227 float get_setup_priority()
const override;
228 float get_loop_priority()
const override;
231 void loop()
override;
233 bool has_sta()
const;
236 #ifdef USE_WIFI_11KV_SUPPORT 237 void set_btm(
bool btm);
238 void set_rrm(
bool rrm);
243 void set_use_address(
const std::string &use_address);
250 for (
auto &it : this->sta_priorities_) {
251 if (it.bssid == bssid)
257 for (
auto &it : this->sta_priorities_) {
258 if (it.bssid == bssid)
264 for (
auto &it : this->sta_priorities_) {
265 if (it.bssid == bssid) {
277 std::string wifi_ssid();
283 static std::string format_mac_addr(
const uint8_t mac[6]);
284 void setup_ap_config_();
285 void print_connect_params_();
289 bool wifi_sta_pre_setup_();
290 bool wifi_apply_output_power_(
float output_power);
291 bool wifi_apply_power_save_();
293 bool wifi_apply_hostname_();
294 bool wifi_sta_connect_(
const WiFiAP &ap);
295 void wifi_pre_setup_();
297 bool wifi_scan_start_();
299 bool wifi_start_ap_(
const WiFiAP &ap);
300 bool wifi_disconnect_();
301 int32_t wifi_channel_();
306 bool is_captive_portal_active_();
307 bool is_esp32_improv_active_();
310 static void wifi_event_callback(System_Event_t *event);
311 void wifi_scan_done_callback_(
void *arg, STATUS
status);
312 static void s_wifi_scan_done_callback(
void *arg, STATUS status);
315 #ifdef USE_ESP32_FRAMEWORK_ARDUINO 316 #if ESP_IDF_VERSION_MAJOR >= 4 317 void wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info);
319 void wifi_event_callback_(system_event_id_t event, system_event_info_t info);
321 void wifi_scan_done_callback_();
324 void wifi_process_event_(IDFWiFiEvent *data);
328 static int s_wifi_scan_result(
void *env,
const cyw43_ev_scan_result_t *result);
329 void wifi_scan_result(
void *env,
const cyw43_ev_scan_result_t *result);
336 bool fast_connect_{
false};
342 uint8_t num_retried_{0};
343 uint32_t last_connected_{0};
344 uint32_t reboot_timeout_{};
345 uint32_t ap_timeout_{};
347 bool error_from_callback_{
false};
349 bool scan_done_{
false};
350 bool ap_setup_{
false};
353 bool has_saved_wifi_settings_{
false};
354 #ifdef USE_WIFI_11KV_SUPPORT 364 bool check(Ts... x)
override;
Nothing has been initialized yet.
This component is responsible for managing the ESP WiFi interface.
void set_priority(float priority)
std::array< uint8_t, 6 > bssid_t
std::string get_use_address()
Get the active network hostname.
float get_priority() const
void set_output_power(float output_power)
const std::vector< WiFiScanResult > & get_scan_result() const
void set_sta_priority(const bssid_t bssid, float priority)
optional< ManualIP > manual_ip_
struct esphome::wifi::SavedWifiSettings PACKED
WiFi is in STA(+AP) mode and currently connecting to an AP a second time.
WiFi is in STA(+AP) mode and successfully connected.
void set_priority(float priority)
network::IPAddress static_ip
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
network::IPAddress gateway
void set_ap_timeout(uint32_t ap_timeout)
std::vector< WiFiScanResult > scan_result_
WiFi is in STA-only mode and currently scanning for APs.
Struct for setting static IPs in WiFiComponent.
network::IPAddress dns1
The first DNS server. 0.0.0.0 for default.
Base class for all automation conditions.
WiFi is in STA(+AP) mode and currently connecting to an AP.
bool has_sta_priority(const bssid_t &bssid)
WiFi is in cooldown mode because something went wrong, scanning will begin after a short period of ti...
optional< bssid_t > bssid_
WiFiComponent * global_wifi_component
optional< uint8_t > channel_
float get_priority() const
ESPPreferenceObject pref_
network::IPAddress dns2
The second DNS server. 0.0.0.0 for default.
std::vector< WiFiSTAPriority > sta_priorities_
bool operator==(optional< T > const &x, optional< U > const &y)
std::vector< WiFiAP > sta_
optional< float > output_power_
network::IPAddress subnet
bool check(Ts... x) override
float get_sta_priority(const bssid_t bssid)
WiFi is in AP-only mode and internal AP is already enabled.
network::IPAddress get_ip_address()