use IPAddress for IPConfiguratio

This commit is contained in:
technyon
2023-03-05 11:06:34 +01:00
parent 2757754531
commit 2dcbf919c8
3 changed files with 23 additions and 22 deletions

View File

@@ -10,6 +10,11 @@ IPConfiguration::IPConfiguration(Preferences *preferences, const bool& firstStar
_preferences->putBool(preference_ip_dhcp_enabled, true); _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: ")); Log->print(F("IP configuration: "));
if(dhcpEnabled()) if(dhcpEnabled())
{ {
@@ -29,22 +34,22 @@ bool IPConfiguration::dhcpEnabled() const
return _preferences->getBool(preference_ip_dhcp_enabled); 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;
} }

View File

@@ -8,12 +8,17 @@ public:
explicit IPConfiguration(Preferences* preferences, const bool& firstStart); explicit IPConfiguration(Preferences* preferences, const bool& firstStart);
bool dhcpEnabled() const; bool dhcpEnabled() const;
String ipAddress() const; const IPAddress ipAddress() const;
String subnet() const; const IPAddress subnet() const;
String defaultGateway() const; const IPAddress defaultGateway() const;
String dnsServer() const; const IPAddress dnsServer() const;
private: private:
Preferences* _preferences = nullptr; Preferences* _preferences = nullptr;
IPAddress _ipAddress;
IPAddress _subnet;
IPAddress _gateway;
IPAddress _dnsServer;
}; };

View File

@@ -71,16 +71,7 @@ void WifiDevice::initialize()
if(!_ipConfiguration->dhcpEnabled()) if(!_ipConfiguration->dhcpEnabled())
{ {
IPAddress address; _wm.setSTAStaticIPConfig(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
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.setAPCallback(clearRtcInitVar); _wm.setAPCallback(clearRtcInitVar);