diff --git a/networkDevices/IPConfiguration.cpp b/networkDevices/IPConfiguration.cpp index 8540c94..4ce384f 100644 --- a/networkDevices/IPConfiguration.cpp +++ b/networkDevices/IPConfiguration.cpp @@ -10,6 +10,11 @@ IPConfiguration::IPConfiguration(Preferences *preferences, const bool& firstStar _preferences->putBool(preference_ip_dhcp_enabled, true); } + _ipAddress.fromString(_preferences->getString(preference_ip_address)); + _subnet.fromString(_preferences->getString(preference_ip_subnet)); + _gateway.fromString(_preferences->getString(preference_ip_gateway)); + _dnsServer.fromString(_preferences->getString(preference_ip_dns_server)); + Log->print(F("IP configuration: ")); if(dhcpEnabled()) { @@ -29,22 +34,22 @@ bool IPConfiguration::dhcpEnabled() const return _preferences->getBool(preference_ip_dhcp_enabled); } -String IPConfiguration::ipAddress() const +const IPAddress IPConfiguration::ipAddress() const { - return _preferences->getString(preference_ip_address); + return _ipAddress; } -String IPConfiguration::subnet() const +const IPAddress IPConfiguration::subnet() const { - return _preferences->getString(preference_ip_subnet); + return _subnet; } -String IPConfiguration::defaultGateway() const +const IPAddress IPConfiguration::defaultGateway() const { - return _preferences->getString(preference_ip_gateway); + return _gateway; } -String IPConfiguration::dnsServer() const +const IPAddress IPConfiguration::dnsServer() const { - return _preferences->getString(preference_ip_dns_server); + return _dnsServer; } diff --git a/networkDevices/IPConfiguration.h b/networkDevices/IPConfiguration.h index 9a95597..ab3b4e7 100644 --- a/networkDevices/IPConfiguration.h +++ b/networkDevices/IPConfiguration.h @@ -8,12 +8,17 @@ public: explicit IPConfiguration(Preferences* preferences, const bool& firstStart); bool dhcpEnabled() const; - String ipAddress() const; - String subnet() const; - String defaultGateway() const; - String dnsServer() const; + const IPAddress ipAddress() const; + const IPAddress subnet() const; + const IPAddress defaultGateway() const; + const IPAddress dnsServer() const; private: Preferences* _preferences = nullptr; + + IPAddress _ipAddress; + IPAddress _subnet; + IPAddress _gateway; + IPAddress _dnsServer; }; diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index a80e020..5ad4df6 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -71,16 +71,7 @@ void WifiDevice::initialize() if(!_ipConfiguration->dhcpEnabled()) { - IPAddress address; - address.fromString(_ipConfiguration->ipAddress()); - IPAddress gateway; - gateway.fromString(_ipConfiguration->defaultGateway()); - IPAddress subnet; - subnet.fromString(_ipConfiguration->subnet()); - IPAddress dns; - dns.fromString(_ipConfiguration->dnsServer()); - - _wm.setSTAStaticIPConfig(address, gateway, subnet, dns); + _wm.setSTAStaticIPConfig(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer()); } _wm.setAPCallback(clearRtcInitVar);