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" 87 #ifdef USE_WIFI_WPA2_EAP 97 #endif // USE_WIFI_WPA2_EAP 103 void set_ssid(
const std::string &
ssid);
106 void set_password(
const std::string &
password);
107 #ifdef USE_WIFI_WPA2_EAP 109 #endif // USE_WIFI_WPA2_EAP 113 void set_hidden(
bool hidden);
114 const std::string &get_ssid()
const;
116 const std::string &get_password()
const;
117 #ifdef USE_WIFI_WPA2_EAP 119 #endif // USE_WIFI_WPA2_EAP 123 bool get_hidden()
const;
129 #ifdef USE_WIFI_WPA2_EAP 131 #endif // USE_WIFI_WPA2_EAP 142 bool matches(
const WiFiAP &config);
144 bool get_matches()
const;
145 void set_matches(
bool matches);
146 const bssid_t &get_bssid()
const;
147 const std::string &get_ssid()
const;
148 uint8_t get_channel()
const;
149 int8_t get_rssi()
const;
150 bool get_with_auth()
const;
151 bool get_is_hidden()
const;
158 bool matches_{
false};
165 float priority_{0.0f};
189 void set_sta(
const WiFiAP &ap);
190 void add_sta(
const WiFiAP &ap);
200 void set_ap(
const WiFiAP &ap);
206 void start_scanning();
207 void check_scanning_finished();
208 void start_connecting(
const WiFiAP &ap,
bool two);
209 void set_fast_connect(
bool fast_connect);
212 void check_connecting_finished();
214 void retry_connect();
216 bool can_proceed()
override;
218 void set_reboot_timeout(uint32_t reboot_timeout);
225 void set_passive_scan(
bool passive);
227 void save_wifi_sta(
const std::string &
ssid,
const std::string &
password);
231 void setup()
override;
233 void dump_config()
override;
235 float get_setup_priority()
const override;
236 float get_loop_priority()
const override;
239 void loop()
override;
241 bool has_sta()
const;
244 #ifdef USE_WIFI_11KV_SUPPORT 245 void set_btm(
bool btm);
246 void set_rrm(
bool rrm);
252 void set_use_address(
const std::string &use_address);
259 for (
auto &it : this->sta_priorities_) {
260 if (it.bssid == bssid)
266 for (
auto &it : this->sta_priorities_) {
267 if (it.bssid == bssid)
273 for (
auto &it : this->sta_priorities_) {
274 if (it.bssid == bssid) {
286 std::string wifi_ssid();
294 static std::string format_mac_addr(
const uint8_t mac[6]);
295 void setup_ap_config_();
296 void print_connect_params_();
300 bool wifi_sta_pre_setup_();
301 bool wifi_apply_output_power_(
float output_power);
302 bool wifi_apply_power_save_();
304 bool wifi_apply_hostname_();
305 bool wifi_sta_connect_(
const WiFiAP &ap);
306 void wifi_pre_setup_();
308 bool wifi_scan_start_(
bool passive);
310 bool wifi_start_ap_(
const WiFiAP &ap);
311 bool wifi_disconnect_();
312 int32_t wifi_channel_();
317 bool is_captive_portal_active_();
318 bool is_esp32_improv_active_();
321 static void wifi_event_callback(System_Event_t *event);
322 void wifi_scan_done_callback_(
void *arg, STATUS
status);
323 static void s_wifi_scan_done_callback(
void *arg, STATUS status);
326 #ifdef USE_ESP32_FRAMEWORK_ARDUINO 327 #if ESP_IDF_VERSION_MAJOR >= 4 328 void wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info);
330 void wifi_event_callback_(system_event_id_t event, system_event_info_t info);
332 void wifi_scan_done_callback_();
335 void wifi_process_event_(IDFWiFiEvent *data);
339 static int s_wifi_scan_result(
void *env,
const cyw43_ev_scan_result_t *result);
340 void wifi_scan_result(
void *env,
const cyw43_ev_scan_result_t *result);
347 bool fast_connect_{
false};
353 uint8_t num_retried_{0};
354 uint32_t last_connected_{0};
355 uint32_t reboot_timeout_{};
356 uint32_t ap_timeout_{};
358 bool error_from_callback_{
false};
360 bool scan_done_{
false};
361 bool ap_setup_{
false};
363 bool passive_scan_{
false};
365 bool has_saved_wifi_settings_{
false};
366 #ifdef USE_WIFI_11KV_SUPPORT
Nothing has been initialized yet.
This component is responsible for managing the ESP WiFi interface.
void set_enable_on_boot(bool enable_on_boot)
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.
void play(Ts... x) override
WiFi is in STA(+AP) mode and successfully connected.
bool check(Ts... x) override
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
void play(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()