From 402e8ea1cec1080496051edd1a271d7405c12885 Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Tue, 5 Dec 2023 20:44:46 +0100 Subject: [PATCH] Ethernet - allow return to DHCP after begin with static IP --- libraries/Ethernet/src/Ethernet.cpp | 6 +++++- libraries/Ethernet/src/Ethernet.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 8d9c51a88..196afa01d 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -8,7 +8,11 @@ int arduino::EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned _initializerCallback(); if (eth_if == nullptr) return 0; } + eth_if->set_dhcp(true); + _begin(mac, timeout, responseTimeout); +} +int arduino::EthernetClass::_begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { if (mac != nullptr) { eth_if->get_emac().set_hwaddr(mac); } @@ -53,7 +57,7 @@ int arduino::EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPA eth_if->set_network(_ip, _netmask, _gateway); eth_if->add_dns_server(_dnsServer1, nullptr); - auto ret = begin(mac, timeout, responseTimeout); + auto ret = _begin(mac, timeout, responseTimeout); return ret; } diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 8352a1c4e..2fc2ef240 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -116,6 +116,8 @@ class EthernetClass : public MbedSocketClass { constexpr static int maintain () { return DHCP_CHECK_NONE; } private: + int _begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout); + volatile EthernetLinkStatus _currentNetworkStatus = Unknown; EthernetInterface net; EthernetInterface *eth_if = &net;