From da0390df6354ab1a5678b276ebc505472a8ae34a Mon Sep 17 00:00:00 2001 From: technyon Date: Sun, 7 Jul 2024 14:08:24 +0200 Subject: [PATCH] fix inital printing of IP address --- src/NukiNetwork.cpp | 10 +++++++++- src/NukiNetwork.h | 1 + src/networkDevices/EthLan8720Device.cpp | 12 +----------- src/networkDevices/EthLan8720Device.h | 1 - src/networkDevices/W5500Device.cpp | 12 +----------- src/networkDevices/W5500Device.h | 1 - 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index 18e8239..e62c0e0 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -380,7 +380,8 @@ bool NukiNetwork::update() break; case ReconnectStatus::Success: memset(WiFi_fallbackDetect, 0, sizeof(WiFi_fallbackDetect)); - Log->println(F("Reconnect successful")); + Log->print(F("Reconnect successful: IP: ")); + Log->println(_device->localIP()); break; case ReconnectStatus::Failure: Log->println(F("Reconnect failed")); @@ -388,6 +389,13 @@ bool NukiNetwork::update() } } + if(_logIp && device()->isConnected() && !_device->localIP().equals("0.0.0.0")) + { + _logIp = false; + Log->print(F("IP: ")); + Log->println(_device->localIP()); + } + if(!_device->mqttConnected() && _device->isConnected()) { if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000) diff --git a/src/NukiNetwork.h b/src/NukiNetwork.h index a962a09..a17ca33 100644 --- a/src/NukiNetwork.h +++ b/src/NukiNetwork.h @@ -167,6 +167,7 @@ private: bool _restartOnDisconnect = false; bool _firstConnect = true; bool _publishDebugInfo = false; + bool _logIp = true; std::vector _subscribedTopics; std::map _initTopics; diff --git a/src/networkDevices/EthLan8720Device.cpp b/src/networkDevices/EthLan8720Device.cpp index 3d45f0b..2503546 100644 --- a/src/networkDevices/EthLan8720Device.cpp +++ b/src/networkDevices/EthLan8720Device.cpp @@ -112,17 +112,7 @@ bool EthLan8720Device::supportsEncryption() bool EthLan8720Device::isConnected() { - bool connected = ETH.linkUp(); - - if(_lastConnected == false && connected == true) - { - Serial.print(F("Ethernet connected. IP address: ")); - Serial.println(ETH.localIP().toString()); - } - - _lastConnected = connected; - - return connected; + return ETH.linkUp(); } ReconnectStatus EthLan8720Device::reconnect() diff --git a/src/networkDevices/EthLan8720Device.h b/src/networkDevices/EthLan8720Device.h index 23e36aa..7e2e178 100644 --- a/src/networkDevices/EthLan8720Device.h +++ b/src/networkDevices/EthLan8720Device.h @@ -72,7 +72,6 @@ private: bool _startAp = false; char* _path; bool _hardwareInitialized = false; - bool _lastConnected = false; const std::string _deviceName; uint8_t _phy_addr; diff --git a/src/networkDevices/W5500Device.cpp b/src/networkDevices/W5500Device.cpp index 13e3374..d206a24 100644 --- a/src/networkDevices/W5500Device.cpp +++ b/src/networkDevices/W5500Device.cpp @@ -180,17 +180,7 @@ bool W5500Device::supportsEncryption() bool W5500Device::isConnected() { - bool connected = (Ethernet.linkStatus() == EthernetLinkStatus::LinkON && _maintainResult == 0 && _hasDHCPAddress); - - if(_lastConnected == false && connected == true) - { - Serial.print(F("Ethernet connected. IP address: ")); - Serial.println(Ethernet.localIP().toString()); - } - - _lastConnected = connected; - - return connected; + return (Ethernet.linkStatus() == EthernetLinkStatus::LinkON && _maintainResult == 0 && _hasDHCPAddress); } void W5500Device::initializeMacAddress(byte *mac) diff --git a/src/networkDevices/W5500Device.h b/src/networkDevices/W5500Device.h index 9c60f50..a1acce5 100644 --- a/src/networkDevices/W5500Device.h +++ b/src/networkDevices/W5500Device.h @@ -48,7 +48,6 @@ private: bool _hasDHCPAddress = false; char* _path; W5500Variant _variant; - bool _lastConnected = false; byte _mac[6]; }; \ No newline at end of file