mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
Disable Ethernet loop polling when connected and stable
This commit is contained in:
@@ -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();
|
||||||
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();
|
||||||
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();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -452,6 +458,8 @@ void EthernetComponent::start_connect_() {
|
|||||||
#endif /* USE_NETWORK_IPV6 */
|
#endif /* USE_NETWORK_IPV6 */
|
||||||
this->connect_begin_ = millis();
|
this->connect_begin_ = millis();
|
||||||
this->status_set_warning("waiting for IP configuration");
|
this->status_set_warning("waiting for IP configuration");
|
||||||
|
// Enable loop during connection phase
|
||||||
|
this->enable_loop();
|
||||||
|
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str());
|
err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str());
|
||||||
@@ -620,6 +628,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;
|
||||||
|
|||||||
Reference in New Issue
Block a user