From 6406e0d5ddce653b77a1070e52482c3b87f6bdff Mon Sep 17 00:00:00 2001 From: Badr Bacem KAABIA Date: Sun, 9 Nov 2025 22:13:27 +0100 Subject: [PATCH] Fix: Clear W5100 IP address on DHCP lease failure This addresses the issue where the device retains a stale, invalid IP address after DHCP lease renewal fails (DHCP_CHECK_RENEW_FAIL or DHCP_CHECK_REBIND_FAIL), which could cause network conflicts or connection issues. The fix sets the IP to 0.0.0.0. Signed-off-by: Badr Bacem KAABIA --- src/Ethernet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Ethernet.cpp b/src/Ethernet.cpp index 8d9ce7fd..ef0ee740 100644 --- a/src/Ethernet.cpp +++ b/src/Ethernet.cpp @@ -135,6 +135,14 @@ int EthernetClass::maintain() SPI.endTransaction(); _dnsServerAddress = _dhcp->getDnsServerIp(); break; + case DHCP_CHECK_RENEW_FAIL: + case DHCP_CHECK_REBIND_FAIL: + // Lease renewal failed; IP is no longer valid. + // Stop using the IP address to avoid conflicts. + SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + W5100.setIPAddress(IPAddress(0,0,0,0).raw_address()); + SPI.endTransaction(); + break; default: //this is actually an error, it will retry though break;