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

@@ -798,10 +798,6 @@ bool NukiNetwork::pathEquals(const char* prefix, const char* path, const char* r
{
char prefixedPath[500];
buildMqttPath(prefixedPath, { prefix, path });
Log->println(prefixedPath);
Log->println(referencePath);
return strcmp(prefixedPath, referencePath) == 0;
}

View File

@@ -185,6 +185,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring lock action.");
return;
}
if(comparePrefixedPath(topic, mqtt_topic_reset) && strcmp(value, "1") == 0)

View File

@@ -136,6 +136,7 @@ void NukiNetworkOpener::onMqttDataReceived(const char* topic, byte* payload, con
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring opener action.");
return;
}
if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))

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;