LAN8720: Add code to wait for IP address

This commit is contained in:
technyon
2024-07-12 13:27:16 +02:00
parent ef878592c1
commit 4165ef8803
5 changed files with 31 additions and 4 deletions

View File

@@ -97,6 +97,34 @@ void EthLan8720Device::initialize()
onDisconnected();
}
});
if(_ipConfiguration->dhcpEnabled())
{
waitForIpAddressWithTimeout();
}
}
void EthLan8720Device::waitForIpAddressWithTimeout()
{
int count = 50;
Log->print(F("LAN8720: Obtaining IP address via DHCP"));
while(count > 0 && localIP().equals("0.0.0.0"))
{
Log->print(F("."));
count--;
delay(100);
}
if(localIP().equals("0.0.0.0"))
{
Log->println(F(" Failed"));
}
else
{
Log->println(localIP());
}
}
void EthLan8720Device::reconfigure()

View File

@@ -67,6 +67,7 @@ public:
private:
void onDisconnected();
void waitForIpAddressWithTimeout();
bool _restartOnDisconnect = false;
bool _startAp = false;