4#if defined(USE_NETWORK) && defined(USE_ESP32)
11#ifdef USE_NETWORK_DEFAULT_ROUTE
14#include "esp_netif_net_stack.h"
15#include "lwip/netif.h"
31 err = esp_netif_init();
33 ESP_LOGE(TAG,
"esp_netif_init failed: (%d) %s", err, esp_err_to_name(err));
37 err = esp_event_loop_create_default();
40 if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
41 ESP_LOGE(TAG,
"esp_event_loop_create_default failed: (%d) %s", err, esp_err_to_name(err));
52 " TCP send buffer: %d bytes",
56#ifdef USE_NETWORK_DEFAULT_ROUTE
60 if (wifi !=
nullptr && wifi->is_connected())
69 if (eth !=
nullptr && eth->is_connected())
83#ifdef USE_NETWORK_PRIMARY_INTERFACE_WIFI
84 esp_netif_t *best = wifi !=
nullptr ? wifi : ethernet;
86 esp_netif_t *best = ethernet !=
nullptr ? ethernet : wifi;
89 if (best !=
nullptr) {
94#ifdef NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT
96 listener->on_active_interface(active);
99 if (best ==
nullptr) {
120 route_is_ours =
static_cast<void *
>(netif_default) == esp_netif_get_netif_impl(best);
125 esp_err_t err = esp_netif_set_default_netif(best);
127 ESP_LOGW(TAG,
"Failed to set default interface: (%d) %s", err, esp_err_to_name(err));
136 ESP_LOGI(TAG,
"Default interface: %s", esp_netif_get_desc(best));
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void mark_failed()
Mark this component as failed.
Helper class to lock the lwIP TCPIP core when making lwIP API calls from non-TCPIP threads.
esp_netif_t * get_esp_netif()
esp_netif handle, used by network for default-route arbitration.
StaticVector< ActiveInterfaceListener *, NETWORK_ACTIVE_INTERFACE_LISTENER_COUNT > active_interface_listeners_
esp_netif_t * default_netif_
uint32_t last_route_check_
NetworkInterface active_interface_
void dump_config() override
static constexpr uint32_t ROUTE_CHECK_INTERVAL_MS
esp_netif_t * get_esp_netif_sta()
esp_netif handle of the station interface, used by network for default-route arbitration.
EthernetComponent * global_eth_component
ESPHOME_LOG_TAG(TAG, "network")
NetworkInterface
The interface holding the default route.
@ NETWORK_INTERFACE_ETHERNET
WiFiComponent * global_wifi_component
Application App
Global storage of Application pointer - only one Application can exist.
struct esp_netif_obj esp_netif_t