mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 14:16:40 +00:00
Disable Ethernet loop polling when connected and stable (#9102)
This commit is contained in:
parent
d527398dae
commit
0ce3621ac0
@ -274,6 +274,9 @@ void EthernetComponent::loop() {
|
|||||||
ESP_LOGW(TAG, "Connection lost; reconnecting");
|
ESP_LOGW(TAG, "Connection lost; reconnecting");
|
||||||
this->state_ = EthernetComponentState::CONNECTING;
|
this->state_ = EthernetComponentState::CONNECTING;
|
||||||
this->start_connect_();
|
this->start_connect_();
|
||||||
|
} else {
|
||||||
|
// When connected and stable, disable the loop to save CPU cycles
|
||||||
|
this->disable_loop();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -397,11 +400,13 @@ void EthernetComponent::eth_event_handler(void *arg, esp_event_base_t event_base
|
|||||||
case ETHERNET_EVENT_START:
|
case ETHERNET_EVENT_START:
|
||||||
event_name = "ETH started";
|
event_name = "ETH started";
|
||||||
global_eth_component->started_ = true;
|
global_eth_component->started_ = true;
|
||||||
|
global_eth_component->enable_loop_soon_any_context();
|
||||||
break;
|
break;
|
||||||
case ETHERNET_EVENT_STOP:
|
case ETHERNET_EVENT_STOP:
|
||||||
event_name = "ETH stopped";
|
event_name = "ETH stopped";
|
||||||
global_eth_component->started_ = false;
|
global_eth_component->started_ = false;
|
||||||
global_eth_component->connected_ = false;
|
global_eth_component->connected_ = false;
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
break;
|
break;
|
||||||
case ETHERNET_EVENT_CONNECTED:
|
case ETHERNET_EVENT_CONNECTED:
|
||||||
event_name = "ETH connected";
|
event_name = "ETH connected";
|
||||||
@ -409,6 +414,7 @@ void EthernetComponent::eth_event_handler(void *arg, esp_event_base_t event_base
|
|||||||
case ETHERNET_EVENT_DISCONNECTED:
|
case ETHERNET_EVENT_DISCONNECTED:
|
||||||
event_name = "ETH disconnected";
|
event_name = "ETH disconnected";
|
||||||
global_eth_component->connected_ = false;
|
global_eth_component->connected_ = false;
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -425,8 +431,10 @@ void EthernetComponent::got_ip_event_handler(void *arg, esp_event_base_t event_b
|
|||||||
global_eth_component->got_ipv4_address_ = true;
|
global_eth_component->got_ipv4_address_ = true;
|
||||||
#if USE_NETWORK_IPV6 && (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
|
#if USE_NETWORK_IPV6 && (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
|
||||||
global_eth_component->connected_ = global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT;
|
global_eth_component->connected_ = global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT;
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
#else
|
#else
|
||||||
global_eth_component->connected_ = true;
|
global_eth_component->connected_ = true;
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
#endif /* USE_NETWORK_IPV6 */
|
#endif /* USE_NETWORK_IPV6 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,8 +447,10 @@ void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_
|
|||||||
#if (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
|
#if (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
|
||||||
global_eth_component->connected_ =
|
global_eth_component->connected_ =
|
||||||
global_eth_component->got_ipv4_address_ && (global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT);
|
global_eth_component->got_ipv4_address_ && (global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT);
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
#else
|
#else
|
||||||
global_eth_component->connected_ = global_eth_component->got_ipv4_address_;
|
global_eth_component->connected_ = global_eth_component->got_ipv4_address_;
|
||||||
|
global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* USE_NETWORK_IPV6 */
|
#endif /* USE_NETWORK_IPV6 */
|
||||||
@ -620,6 +630,7 @@ bool EthernetComponent::powerdown() {
|
|||||||
}
|
}
|
||||||
this->connected_ = false;
|
this->connected_ = false;
|
||||||
this->started_ = false;
|
this->started_ = false;
|
||||||
|
// No need to enable_loop() here as this is only called during shutdown/reboot
|
||||||
if (this->phy_->pwrctl(this->phy_, false) != ESP_OK) {
|
if (this->phy_->pwrctl(this->phy_, false) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Error powering down ethernet PHY");
|
ESP_LOGE(TAG, "Error powering down ethernet PHY");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user