3#if defined(USE_ETHERNET) && defined(USE_RP2040)
13#include <lwip/netif.h>
17static const char *
const TAG =
"ethernet";
27 rp2040::RP2040GPIOPin reset_pin;
31 reset_pin.digital_write(
false);
33 reset_pin.digital_write(
true);
39#if defined(USE_ETHERNET_W5500)
41#elif defined(USE_ETHERNET_W5100)
43#elif defined(USE_ETHERNET_ENC28J60)
51#ifdef USE_ETHERNET_MANUAL_IP
58 this->
eth_->config(ip, gateway, subnet, dns1, dns2);
67 success = this->
eth_->begin();
71 ESP_LOGE(TAG,
"Failed to initialize Ethernet");
79 this->
eth_->setDefault(
true);
103#if defined(USE_ETHERNET_W5100)
108 bool link_up = this->
eth_->linkStatus() == LinkON;
110 bool has_ip = this->
eth_->connected();
124#ifdef USE_ETHERNET_IP_STATE_LISTENERS
135 ESP_LOGI(TAG,
"Starting connection");
142 ESP_LOGI(TAG,
"Stopped connection");
146 ESP_LOGI(TAG,
"Connected");
151#ifdef USE_ETHERNET_CONNECT_TRIGGER
155 ESP_LOGW(TAG,
"Connecting failed; reconnecting");
161 ESP_LOGI(TAG,
"Stopped connection");
163#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
167 ESP_LOGW(TAG,
"Connection lost; reconnecting");
170#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
181 const char *type_str =
"Unknown";
182#if defined(USE_ETHERNET_W5500)
184#elif defined(USE_ETHERNET_W5100)
186#elif defined(USE_ETHERNET_ENC28J60)
187 type_str =
"ENC28J60";
206 if (this->
eth_ !=
nullptr) {
208 addresses[0] = network::IPAddress(this->
eth_->localIP());
215 const ip_addr_t *dns_ip = dns_getserver(num);
220 if (this->
eth_ !=
nullptr) {
221 this->
eth_->macAddress(mac);
227std::string EthernetComponent::get_eth_mac_address_pretty() {
228 char buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
233 std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buf) {
246#ifdef USE_ETHERNET_ENC28J60
256 ESP_LOGI(TAG,
"Powering down ethernet");
257 if (this->
eth_ !=
nullptr) {
272#ifdef USE_ETHERNET_MANUAL_IP
280 dns_setserver(0, &d);
285 dns_setserver(1, &d);
297 if (this->
eth_ ==
nullptr) {
301 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
302 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
303 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
304 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
305 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
306 char mac_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
312 auto *netif = this->
eth_->getNetIf();
313 ip_addr = netif->ip_addr;
314 netmask = netif->netmask;
316 dns1_addr = *dns_getserver(0);
317 dns2_addr = *dns_getserver(1);
328 network::IPAddress(&netmask).str_to(subnet_buf), network::IPAddress(&gw).str_to(gateway_buf),
329 network::IPAddress(&dns1_addr).str_to(dns1_buf), network::IPAddress(&dns2_addr).str_to(dns2_buf),
330 this->get_eth_mac_address_pretty_into_buffer(mac_buf));
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
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.
void status_set_warning()
void status_clear_warning()
constexpr const char * c_str() const
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
Trigger disconnect_trigger_
void set_clk_pin(uint8_t clk_pin)
void get_eth_mac_address_raw(uint8_t *mac)
eth_duplex_t get_duplex_mode()
void notify_ip_state_listeners_()
static constexpr uint32_t LINK_CHECK_INTERVAL
network::IPAddresses get_ip_addresses()
void dump_connect_params_()
EthernetComponentState state_
network::IPAddress get_dns_address(uint8_t num)
void set_reset_pin(uint8_t reset_pin)
optional< ManualIP > manual_ip_
eth_speed_t get_link_speed()
void dump_config() override
uint32_t last_link_check_
void set_interrupt_pin(uint8_t interrupt_pin)
static constexpr uint32_t RESET_DELAY_MS
void set_miso_pin(uint8_t miso_pin)
optional< std::array< uint8_t, 6 > > fixed_mac_
void set_cs_pin(uint8_t cs_pin)
void set_mosi_pin(uint8_t mosi_pin)
ESPDEPRECATED("Use get_eth_mac_address_pretty_into_buffer() instead. Removed in 2026.9.0", "2026.3.0") std const char * get_eth_mac_address_pretty_into_buffer(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf)
std::array< IPAddress, 5 > IPAddresses
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
char * format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase, colon separators)