[wifi] Fix for wifi_info when static IP is configured (#12576)
This commit is contained in:
committed by
Jonathan Swoboda
parent
dc943d7e7a
commit
1922455fa7
@@ -528,6 +528,16 @@ void WiFiComponent::wifi_event_callback(System_Event_t *event) {
|
|||||||
for (auto *listener : global_wifi_component->connect_state_listeners_) {
|
for (auto *listener : global_wifi_component->connect_state_listeners_) {
|
||||||
listener->on_wifi_connect_state(global_wifi_component->wifi_ssid(), global_wifi_component->wifi_bssid());
|
listener->on_wifi_connect_state(global_wifi_component->wifi_ssid(), global_wifi_component->wifi_bssid());
|
||||||
}
|
}
|
||||||
|
// For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
|
||||||
|
#ifdef USE_WIFI_MANUAL_IP
|
||||||
|
if (const WiFiAP *config = global_wifi_component->get_selected_sta_();
|
||||||
|
config && config->get_manual_ip().has_value()) {
|
||||||
|
for (auto *listener : global_wifi_component->ip_state_listeners_) {
|
||||||
|
listener->on_ip_state(global_wifi_component->wifi_sta_ip_addresses(),
|
||||||
|
global_wifi_component->get_dns_address(0), global_wifi_component->get_dns_address(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -739,6 +739,14 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
|||||||
for (auto *listener : this->connect_state_listeners_) {
|
for (auto *listener : this->connect_state_listeners_) {
|
||||||
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
||||||
}
|
}
|
||||||
|
// For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
|
||||||
|
#ifdef USE_WIFI_MANUAL_IP
|
||||||
|
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||||
|
for (auto *listener : this->ip_state_listeners_) {
|
||||||
|
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||||
|
|||||||
@@ -305,6 +305,14 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
|
|||||||
for (auto *listener : this->connect_state_listeners_) {
|
for (auto *listener : this->connect_state_listeners_) {
|
||||||
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
||||||
}
|
}
|
||||||
|
// For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
|
||||||
|
#ifdef USE_WIFI_MANUAL_IP
|
||||||
|
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||||
|
for (auto *listener : this->ip_state_listeners_) {
|
||||||
|
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,6 +259,15 @@ void WiFiComponent::wifi_loop_() {
|
|||||||
for (auto *listener : this->connect_state_listeners_) {
|
for (auto *listener : this->connect_state_listeners_) {
|
||||||
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
listener->on_wifi_connect_state(this->wifi_ssid(), this->wifi_bssid());
|
||||||
}
|
}
|
||||||
|
// For static IP configurations, notify IP listeners immediately as the IP is already configured
|
||||||
|
#ifdef USE_WIFI_MANUAL_IP
|
||||||
|
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||||
|
s_sta_had_ip = true;
|
||||||
|
for (auto *listener : this->ip_state_listeners_) {
|
||||||
|
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} else if (!is_connected && s_sta_was_connected) {
|
} else if (!is_connected && s_sta_was_connected) {
|
||||||
// Just disconnected
|
// Just disconnected
|
||||||
|
|||||||
Reference in New Issue
Block a user