3#if defined(USE_ETHERNET) && defined(USE_RP2)
13#include <lwip/netif.h>
21#if !defined(USE_ETHERNET_W6300) && defined(USE_ETHERNET_SPI)
30#ifdef USE_ETHERNET_SPI
33 rp2::RP2GPIOPin reset_pin;
37 reset_pin.digital_write(
false);
39 reset_pin.digital_write(
true);
46#if defined(USE_ETHERNET_W5500)
48#elif defined(USE_ETHERNET_W5100)
50#elif defined(USE_ETHERNET_W6100)
52#elif defined(USE_ETHERNET_W6300)
54#elif defined(USE_ETHERNET_ENC28J60)
56#elif defined(USE_ETHERNET_USB)
57 this->
eth_ =
new NCMEthernetlwIP();
64#ifdef USE_ETHERNET_MANUAL_IP
67 this->
eth_->config(IPAddress(manual_ip.static_ip), IPAddress(manual_ip.gateway), IPAddress(manual_ip.subnet),
68 IPAddress(manual_ip.dns1), IPAddress(manual_ip.dns2));
77 success = this->
eth_->begin();
81 ESP_LOGE(TAG,
"Failed to initialize Ethernet");
89 this->
eth_->setDefault(
true);
113#if defined(USE_ETHERNET_W5100)
118 bool link_up = this->
eth_->linkStatus() == LinkON;
120 bool has_ip = this->
eth_->connected();
134#ifdef USE_ETHERNET_IP_STATE_LISTENERS
145 ESP_LOGI(TAG,
"Starting connection");
152 ESP_LOGI(TAG,
"Stopped connection");
156 ESP_LOGI(TAG,
"Connected");
161#ifdef USE_ETHERNET_CONNECT_TRIGGER
166 ESP_LOGW(TAG,
"Connecting failed; reconnecting");
172 ESP_LOGI(TAG,
"Stopped connection");
174#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
179 ESP_LOGW(TAG,
"Connection lost; reconnecting");
182#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
194#if defined(USE_ETHERNET_W5500)
195 const char *type_str =
"W5500";
196#elif defined(USE_ETHERNET_W5100)
197 const char *type_str =
"W5100";
198#elif defined(USE_ETHERNET_W6100)
199 const char *type_str =
"W6100";
200#elif defined(USE_ETHERNET_W6300)
201 const char *type_str =
"W6300";
202#elif defined(USE_ETHERNET_ENC28J60)
203 const char *type_str =
"ENC28J60";
204#elif defined(USE_ETHERNET_USB)
205 const char *type_str =
"USB";
207 const char *type_str =
"Unknown";
209#if defined(USE_ETHERNET_W6300)
213 " Type: %s (PIO QSPI)\n"
218#elif defined(USE_ETHERNET_SPI)
243 if (this->
eth_ !=
nullptr) {
245 addresses[0] = network::IPAddress(this->
eth_->localIP());
252 const ip_addr_t *dns_ip = dns_getserver(num);
257 if (this->
eth_ !=
nullptr) {
258 this->
eth_->macAddress(mac);
260 memset(mac, 0, MAC_ADDRESS_SIZE);
265 std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buf) {
266 uint8_t mac[MAC_ADDRESS_SIZE];
278#if defined(USE_ETHERNET_ENC28J60) || defined(USE_ETHERNET_USB)
288 ESP_LOGI(TAG,
"Powering down ethernet");
289#ifndef USE_ETHERNET_USB
291 if (this->
eth_ !=
nullptr) {
307#ifdef USE_ETHERNET_MANUAL_IP
312 if (manual_ip.dns1.is_set()) {
314 dns_setserver(0, &d);
316 if (manual_ip.dns2.is_set()) {
318 dns_setserver(1, &d);
329 if (this->
eth_ ==
nullptr) {
333 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
334 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
335 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
336 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
337 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
338 char mac_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
344 auto *netif = this->
eth_->getNetIf();
345 ip_addr = netif->ip_addr;
346 netmask = netif->netmask;
348 dns1_addr = *dns_getserver(0);
349 dns2_addr = *dns_getserver(1);
360 network::IPAddress(&netmask).str_to(subnet_buf), network::IPAddress(&gw).str_to(gateway_buf),
361 network::IPAddress(&dns1_addr).str_to(dns1_buf), network::IPAddress(&dns2_addr).str_to(dns2_buf),
362 this->get_eth_mac_address_pretty_into_buffer(mac_buf));
371 ESP_LOGW(TAG,
"enable_on_boot/disable not supported");
378 ESP_LOGW(TAG,
"enable_on_boot/disable not supported");
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 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)
eth_speed_t get_link_speed()
void dump_config() override
uint32_t last_link_check_
optional< std::array< uint8_t, MAC_ADDRESS_SIZE > > fixed_mac_
static constexpr uint32_t RESET_DELAY_MS
void notify_connect_state_listeners_(bool connected)
const char * get_eth_mac_address_pretty_into_buffer(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf)
LwipIntfDev< Wiznet6300NoSPI > Wiznet6300lwIPFixed
ESPHOME_LOG_TAG(TAG, "ethernet")
ManualIP load_manual_ip()
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)