From 4165ef8803f11221f4039313385cc2f5b726ae4a Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 12 Jul 2024 13:27:16 +0200 Subject: [PATCH] LAN8720: Add code to wait for IP address --- src/NukiNetwork.cpp | 4 ---- src/NukiNetworkLock.cpp | 1 + src/NukiNetworkOpener.cpp | 1 + src/networkDevices/EthLan8720Device.cpp | 28 +++++++++++++++++++++++++ src/networkDevices/EthLan8720Device.h | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index e8408af..41ed4b8 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -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; } diff --git a/src/NukiNetworkLock.cpp b/src/NukiNetworkLock.cpp index 5990dc9..7780b5d 100644 --- a/src/NukiNetworkLock.cpp +++ b/src/NukiNetworkLock.cpp @@ -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) diff --git a/src/NukiNetworkOpener.cpp b/src/NukiNetworkOpener.cpp index 24fbc03..fafc239 100644 --- a/src/NukiNetworkOpener.cpp +++ b/src/NukiNetworkOpener.cpp @@ -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)) diff --git a/src/networkDevices/EthLan8720Device.cpp b/src/networkDevices/EthLan8720Device.cpp index 2503546..812454a 100644 --- a/src/networkDevices/EthLan8720Device.cpp +++ b/src/networkDevices/EthLan8720Device.cpp @@ -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() diff --git a/src/networkDevices/EthLan8720Device.h b/src/networkDevices/EthLan8720Device.h index edff988..5cc64a2 100644 --- a/src/networkDevices/EthLan8720Device.h +++ b/src/networkDevices/EthLan8720Device.h @@ -67,6 +67,7 @@ public: private: void onDisconnected(); + void waitForIpAddressWithTimeout(); bool _restartOnDisconnect = false; bool _startAp = false;