mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge branch 'disable_ethernet_loop' into integration
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_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 */ | ||||||
| @@ -452,6 +462,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 +632,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