ESPHome 2025.8.0b1
|
This component is responsible for managing the ESP WiFi interface. More...
#include <wifi_component.h>
Public Member Functions | |
WiFiComponent () | |
Construct a WiFiComponent. | |
void | set_sta (const WiFiAP &ap) |
WiFiAP | get_sta () |
void | add_sta (const WiFiAP &ap) |
void | clear_sta () |
void | set_ap (const WiFiAP &ap) |
Setup an Access Point that should be created if no connection to a station can be made. | |
WiFiAP | get_ap () |
void | enable () |
void | disable () |
bool | is_disabled () |
void | start_scanning () |
void | check_scanning_finished () |
void | start_connecting (const WiFiAP &ap, bool two) |
void | set_fast_connect (bool fast_connect) |
void | set_ap_timeout (uint32_t ap_timeout) |
void | check_connecting_finished () |
void | retry_connect () |
bool | can_proceed () override |
void | set_reboot_timeout (uint32_t reboot_timeout) |
bool | is_connected () |
void | set_power_save_mode (WiFiPowerSaveMode power_save) |
void | set_output_power (float output_power) |
void | set_passive_scan (bool passive) |
void | save_wifi_sta (const std::string &ssid, const std::string &password) |
void | setup () override |
Setup WiFi interface. | |
void | start () |
void | dump_config () override |
void | restart_adapter () |
float | get_setup_priority () const override |
WIFI setup_priority. | |
float | get_loop_priority () const override |
void | loop () override |
Reconnect WiFi if required. | |
bool | has_sta () const |
bool | has_ap () const |
void | set_btm (bool btm) |
void | set_rrm (bool rrm) |
network::IPAddress | get_dns_address (int num) |
network::IPAddresses | get_ip_addresses () |
std::string | get_use_address () const |
void | set_use_address (const std::string &use_address) |
const std::vector< WiFiScanResult > & | get_scan_result () const |
network::IPAddress | wifi_soft_ap_ip () |
bool | has_sta_priority (const bssid_t &bssid) |
float | get_sta_priority (const bssid_t bssid) |
void | set_sta_priority (const bssid_t bssid, float priority) |
network::IPAddresses | wifi_sta_ip_addresses () |
std::string | wifi_ssid () |
bssid_t | wifi_bssid () |
int8_t | wifi_rssi () |
void | set_enable_on_boot (bool enable_on_boot) |
Trigger * | get_connect_trigger () const |
Trigger * | get_disconnect_trigger () const |
int32_t | get_wifi_channel () |
![]() | |
float | get_actual_setup_priority () const |
void | set_setup_priority (float priority) |
void | call () |
virtual void | on_shutdown () |
virtual void | on_safe_shutdown () |
virtual bool | teardown () |
Called during teardown to allow component to gracefully finish operations. | |
virtual void | on_powerdown () |
Called after teardown is complete to power down hardware. | |
uint8_t | get_component_state () const |
void | reset_to_construction_state () |
Reset this component back to the construction state to allow setup to run again. | |
bool | is_in_loop_state () const |
Check if this component has completed setup and is in the loop state. | |
virtual void | mark_failed () |
Mark this component as failed. | |
void | mark_failed (const char *message) |
void | disable_loop () |
Disable this component's loop. | |
void | enable_loop () |
Enable this component's loop. | |
void | enable_loop_soon_any_context () |
Thread and ISR-safe version of enable_loop() that can be called from any context. | |
bool | is_failed () const |
bool | is_ready () const |
bool | status_has_warning () const |
bool | status_has_error () const |
void | status_set_warning (const char *message=nullptr) |
void | status_set_error (const char *message=nullptr) |
void | status_clear_warning () |
void | status_clear_error () |
void | status_momentary_warning (const std::string &name, uint32_t length=5000) |
void | status_momentary_error (const std::string &name, uint32_t length=5000) |
bool | has_overridden_loop () const |
void | set_component_source (const char *source) |
Set where this component was loaded from for some debug messages. | |
const char * | get_component_source () const |
Get the integration where this component was declared as a string. | |
bool | should_warn_of_blocking (uint32_t blocking_time) |
Protected Member Functions | |
void | setup_ap_config_ () |
void | print_connect_params_ () |
void | wifi_loop_ () |
bool | wifi_mode_ (optional< bool > sta, optional< bool > ap) |
bool | wifi_sta_pre_setup_ () |
bool | wifi_apply_output_power_ (float output_power) |
bool | wifi_apply_power_save_ () |
bool | wifi_sta_ip_config_ (optional< ManualIP > manual_ip) |
bool | wifi_apply_hostname_ () |
bool | wifi_sta_connect_ (const WiFiAP &ap) |
void | wifi_pre_setup_ () |
WiFiSTAConnectStatus | wifi_sta_connect_status_ () |
bool | wifi_scan_start_ (bool passive) |
bool | wifi_ap_ip_config_ (optional< ManualIP > manual_ip) |
bool | wifi_start_ap_ (const WiFiAP &ap) |
bool | wifi_disconnect_ () |
network::IPAddress | wifi_subnet_mask_ () |
network::IPAddress | wifi_gateway_ip_ () |
network::IPAddress | wifi_dns_ip_ (int num) |
bool | is_captive_portal_active_ () |
bool | is_esp32_improv_active_ () |
bool | load_fast_connect_settings_ () |
void | save_fast_connect_settings_ () |
void | wifi_scan_done_callback_ (void *arg, STATUS status) |
void | wifi_event_callback_ (arduino_event_id_t event, arduino_event_info_t info) |
void | wifi_scan_done_callback_ () |
void | wifi_process_event_ (IDFWiFiEvent *data) |
void | wifi_scan_result (void *env, const cyw43_ev_scan_result_t *result) |
void | wifi_event_callback_ (arduino_event_id_t event, arduino_event_info_t info) |
void | wifi_scan_done_callback_ () |
![]() | |
virtual void | call_loop () |
virtual void | call_setup () |
virtual void | call_dump_config () |
void | set_component_state_ (uint8_t state) |
Helper to set component state (clears state bits and sets new state) | |
void | set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f) |
Set an interval function with a unique name. | |
void | set_interval (const char *name, uint32_t interval, std::function< void()> &&f) |
Set an interval function with a const char* name. | |
void | set_interval (uint32_t interval, std::function< void()> &&f) |
bool | cancel_interval (const std::string &name) |
Cancel an interval function. | |
bool | cancel_interval (const char *name) |
void | set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f) |
Set an retry function with a unique name. | |
void | set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f) |
bool | cancel_retry (const std::string &name) |
Cancel a retry function. | |
void | set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f) |
Set a timeout function with a unique name. | |
void | set_timeout (const char *name, uint32_t timeout, std::function< void()> &&f) |
Set a timeout function with a const char* name. | |
void | set_timeout (uint32_t timeout, std::function< void()> &&f) |
bool | cancel_timeout (const std::string &name) |
Cancel a timeout function. | |
bool | cancel_timeout (const char *name) |
void | defer (const std::string &name, std::function< void()> &&f) |
Defer a callback to the next loop() call. | |
void | defer (const char *name, std::function< void()> &&f) |
Defer a callback to the next loop() call with a const char* name. | |
void | defer (std::function< void()> &&f) |
Defer a callback to the next loop() call. | |
bool | cancel_defer (const std::string &name) |
Cancel a defer callback using the specified name, name must not be empty. | |
Static Protected Member Functions | |
static void | wifi_event_callback (System_Event_t *event) |
static void | s_wifi_scan_done_callback (void *arg, STATUS status) |
static int | s_wifi_scan_result (void *env, const cyw43_ev_scan_result_t *result) |
Protected Attributes | |
std::string | use_address_ |
std::vector< WiFiAP > | sta_ |
std::vector< WiFiSTAPriority > | sta_priorities_ |
std::vector< WiFiScanResult > | scan_result_ |
WiFiAP | selected_ap_ |
WiFiAP | ap_ |
optional< float > | output_power_ |
ESPPreferenceObject | pref_ |
ESPPreferenceObject | fast_connect_pref_ |
uint32_t | action_started_ |
uint32_t | last_connected_ {0} |
uint32_t | reboot_timeout_ {} |
uint32_t | ap_timeout_ {} |
WiFiComponentState | state_ {WIFI_COMPONENT_STATE_OFF} |
WiFiPowerSaveMode | power_save_ {WIFI_POWER_SAVE_NONE} |
uint8_t | num_retried_ {0} |
uint8_t | ap_index_ {0} |
uint8_t | num_ipv6_addresses_ {0} |
bool | fast_connect_ {false} |
bool | trying_loaded_ap_ {false} |
bool | retry_hidden_ {false} |
bool | has_ap_ {false} |
bool | handled_connected_state_ {false} |
bool | error_from_callback_ {false} |
bool | scan_done_ {false} |
bool | ap_setup_ {false} |
bool | passive_scan_ {false} |
bool | has_saved_wifi_settings_ {false} |
bool | btm_ {false} |
bool | rrm_ {false} |
bool | enable_on_boot_ |
bool | got_ipv4_address_ {false} |
Trigger * | connect_trigger_ {new Trigger<>()} |
Trigger * | disconnect_trigger_ {new Trigger<>()} |
![]() | |
const char * | component_source_ {nullptr} |
uint16_t | warn_if_blocking_over_ {WARN_IF_BLOCKING_OVER_MS} |
Warn if blocked for this many ms (max 65.5s) | |
uint8_t | component_state_ {0x00} |
State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION, 0x01=SETUP, 0x02=LOOP, 0x03=FAILED, 0x04=LOOP_DONE) Bit 3: STATUS_LED_WARNING Bit 4: STATUS_LED_ERROR Bits 5-7: Unused - reserved for future expansion. | |
volatile bool | pending_enable_loop_ {false} |
ISR-safe flag for enable_loop_soon_any_context. | |
This component is responsible for managing the ESP WiFi interface.
Definition at line 207 of file wifi_component.h.
esphome::wifi::WiFiComponent::WiFiComponent | ( | ) |
Construct a WiFiComponent.
Definition at line 223 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::add_sta | ( | const WiFiAP & | ap | ) |
Definition at line 306 of file wifi_component.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 787 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::check_connecting_finished | ( | ) |
Definition at line 663 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::check_scanning_finished | ( | ) |
Definition at line 558 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::clear_sta | ( | ) |
Definition at line 311 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::disable | ( | ) |
Definition at line 491 of file wifi_component.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 658 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::enable | ( | ) |
Definition at line 481 of file wifi_component.cpp.
|
inline |
Definition at line 226 of file wifi_component.h.
|
inline |
Definition at line 320 of file wifi_component.h.
|
inline |
Definition at line 321 of file wifi_component.h.
network::IPAddress esphome::wifi::WiFiComponent::get_dns_address | ( | int | num | ) |
Definition at line 243 of file wifi_component.cpp.
network::IPAddresses esphome::wifi::WiFiComponent::get_ip_addresses | ( | ) |
Definition at line 232 of file wifi_component.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 302 of file wifi_component.cpp.
|
inline |
Definition at line 281 of file wifi_component.h.
|
overridevirtual |
WIFI setup_priority.
Reimplemented from esphome::Component.
Definition at line 45 of file wifi_component.cpp.
|
inline |
Definition at line 213 of file wifi_component.h.
|
inline |
Definition at line 292 of file wifi_component.h.
std::string esphome::wifi::WiFiComponent::get_use_address | ( | ) | const |
Definition at line 248 of file wifi_component.cpp.
int32_t esphome::wifi::WiFiComponent::get_wifi_channel | ( | ) |
Definition at line 857 of file wifi_component_esp32_arduino.cpp.
bool esphome::wifi::WiFiComponent::has_ap | ( | ) | const |
Definition at line 225 of file wifi_component.cpp.
bool esphome::wifi::WiFiComponent::has_sta | ( | ) | const |
Definition at line 226 of file wifi_component.cpp.
|
inline |
Definition at line 285 of file wifi_component.h.
|
protected |
Definition at line 802 of file wifi_component.cpp.
bool esphome::wifi::WiFiComponent::is_connected | ( | ) |
Definition at line 794 of file wifi_component.cpp.
bool esphome::wifi::WiFiComponent::is_disabled | ( | ) |
Definition at line 501 of file wifi_component.cpp.
|
protected |
Definition at line 809 of file wifi_component.cpp.
|
protected |
Definition at line 817 of file wifi_component.cpp.
|
overridevirtual |
Reconnect WiFi if required.
Reimplemented from esphome::Component.
Definition at line 135 of file wifi_component.cpp.
|
protected |
Definition at line 439 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::restart_adapter | ( | ) |
Definition at line 127 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::retry_connect | ( | ) |
Definition at line 737 of file wifi_component.cpp.
|
staticprotected |
Definition at line 687 of file wifi_component_esp8266.cpp.
|
staticprotected |
Definition at line 115 of file wifi_component_pico_w.cpp.
|
protected |
Definition at line 835 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::save_wifi_sta | ( | const std::string & | ssid, |
const std::string & | password ) |
Definition at line 312 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::set_ap | ( | const WiFiAP & | ap | ) |
Setup an Access Point that should be created if no connection to a station can be made.
This can also be used without set_sta(). Then the AP will always be active.
If both STA and AP are defined, then both will be enabled at startup, but if a connection to a station can be made, the AP will be turned off again.
Definition at line 296 of file wifi_component.cpp.
|
inline |
Definition at line 236 of file wifi_component.h.
void esphome::wifi::WiFiComponent::set_btm | ( | bool | btm | ) |
Definition at line 229 of file wifi_component.cpp.
|
inline |
Definition at line 318 of file wifi_component.h.
void esphome::wifi::WiFiComponent::set_fast_connect | ( | bool | fast_connect | ) |
Definition at line 227 of file wifi_component.cpp.
|
inline |
Definition at line 249 of file wifi_component.h.
void esphome::wifi::WiFiComponent::set_passive_scan | ( | bool | passive | ) |
Definition at line 800 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::set_power_save_mode | ( | WiFiPowerSaveMode | power_save | ) |
Definition at line 798 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::set_reboot_timeout | ( | uint32_t | reboot_timeout | ) |
Definition at line 793 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::set_rrm | ( | bool | rrm | ) |
Definition at line 230 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::set_sta | ( | const WiFiAP & | ap | ) |
Definition at line 307 of file wifi_component.cpp.
|
inline |
Definition at line 299 of file wifi_component.h.
void esphome::wifi::WiFiComponent::set_use_address | ( | const std::string & | use_address | ) |
Definition at line 254 of file wifi_component.cpp.
|
overridevirtual |
Setup WiFi interface.
Reimplemented from esphome::Component.
Definition at line 47 of file wifi_component.cpp.
|
protected |
Definition at line 257 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::start | ( | ) |
Definition at line 59 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::start_connecting | ( | const WiFiAP & | ap, |
bool | two ) |
Definition at line 326 of file wifi_component.cpp.
void esphome::wifi::WiFiComponent::start_scanning | ( | ) |
Definition at line 503 of file wifi_component.cpp.
Definition at line 727 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 374 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 115 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 120 of file wifi_component_esp32_arduino.cpp.
bssid_t esphome::wifi::WiFiComponent::wifi_bssid | ( | ) |
Definition at line 846 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 844 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 860 of file wifi_component_esp32_arduino.cpp.
|
staticprotected |
Definition at line 492 of file wifi_component_esp8266.cpp.
|
protected |
Definition at line 525 of file wifi_component_esp32_arduino.cpp.
|
protected |
|
protected |
Definition at line 859 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 503 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 54 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 41 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 683 of file wifi_component_esp_idf.cpp.
int8_t esphome::wifi::WiFiComponent::wifi_rssi | ( | ) |
Definition at line 856 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 703 of file wifi_component_esp32_arduino.cpp.
|
protected |
|
protected |
Definition at line 691 of file wifi_component_esp8266.cpp.
|
protected |
Definition at line 120 of file wifi_component_pico_w.cpp.
|
protected |
Definition at line 689 of file wifi_component_esp32_arduino.cpp.
network::IPAddress esphome::wifi::WiFiComponent::wifi_soft_ap_ip | ( | ) |
Definition at line 837 of file wifi_component_esp32_arduino.cpp.
std::string esphome::wifi::WiFiComponent::wifi_ssid | ( | ) |
Definition at line 855 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 137 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 673 of file wifi_component_esp32_arduino.cpp.
network::IPAddresses esphome::wifi::WiFiComponent::wifi_sta_ip_addresses | ( | ) |
Definition at line 349 of file wifi_component_esp32_arduino.cpp.
Definition at line 281 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 106 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 789 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 858 of file wifi_component_esp32_arduino.cpp.
|
protected |
Definition at line 396 of file wifi_component.h.
|
protected |
Definition at line 390 of file wifi_component.h.
|
protected |
Definition at line 405 of file wifi_component.h.
|
protected |
Definition at line 418 of file wifi_component.h.
|
protected |
Definition at line 399 of file wifi_component.h.
|
protected |
Definition at line 422 of file wifi_component.h.
Definition at line 429 of file wifi_component.h.
Definition at line 430 of file wifi_component.h.
|
protected |
Definition at line 425 of file wifi_component.h.
|
protected |
Definition at line 416 of file wifi_component.h.
|
protected |
Definition at line 411 of file wifi_component.h.
|
protected |
Definition at line 393 of file wifi_component.h.
|
protected |
Definition at line 426 of file wifi_component.h.
|
protected |
Definition at line 415 of file wifi_component.h.
|
protected |
Definition at line 414 of file wifi_component.h.
|
protected |
Definition at line 420 of file wifi_component.h.
|
protected |
Definition at line 397 of file wifi_component.h.
|
protected |
Definition at line 407 of file wifi_component.h.
|
protected |
Definition at line 404 of file wifi_component.h.
|
protected |
Definition at line 391 of file wifi_component.h.
|
protected |
Definition at line 419 of file wifi_component.h.
|
protected |
Definition at line 403 of file wifi_component.h.
|
protected |
Definition at line 392 of file wifi_component.h.
|
protected |
Definition at line 398 of file wifi_component.h.
|
protected |
Definition at line 413 of file wifi_component.h.
|
protected |
Definition at line 423 of file wifi_component.h.
|
protected |
Definition at line 417 of file wifi_component.h.
|
protected |
Definition at line 388 of file wifi_component.h.
|
protected |
Definition at line 389 of file wifi_component.h.
|
protected |
Definition at line 386 of file wifi_component.h.
|
protected |
Definition at line 387 of file wifi_component.h.
|
protected |
Definition at line 402 of file wifi_component.h.
|
protected |
Definition at line 412 of file wifi_component.h.
|
protected |
Definition at line 385 of file wifi_component.h.