add static IP for W5500
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
#include "../PreferencesKeys.h"
|
||||
#include "../Logger.h"
|
||||
|
||||
IPConfiguration::IPConfiguration(Preferences *preferences, const bool& firstStart)
|
||||
IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||
: _preferences(preferences)
|
||||
{
|
||||
if(firstStart)
|
||||
if(_preferences->getString(preference_ip_address).length() <= 0)
|
||||
{
|
||||
Log->println("IP address empty, falling back to DHCP.");
|
||||
_preferences->putBool(preference_ip_dhcp_enabled, true);
|
||||
}
|
||||
|
||||
@@ -23,9 +24,9 @@ IPConfiguration::IPConfiguration(Preferences *preferences, const bool& firstStar
|
||||
else
|
||||
{
|
||||
Log->print(F("IP address: ")); Log->print(ipAddress());
|
||||
Log->print(F("Subnet: ")); Log->print(subnet());
|
||||
Log->print(F("Gateway: ")); Log->print(defaultGateway());
|
||||
Log->print(F("DNS: ")); Log->println(dnsServer());
|
||||
Log->print(F(", Subnet: ")); Log->print(subnet());
|
||||
Log->print(F(", Gateway: ")); Log->print(defaultGateway());
|
||||
Log->print(F(", DNS: ")); Log->println(dnsServer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
class IPConfiguration
|
||||
{
|
||||
public:
|
||||
explicit IPConfiguration(Preferences* preferences, const bool& firstStart);
|
||||
explicit IPConfiguration(Preferences* preferences);
|
||||
|
||||
bool dhcpEnabled() const;
|
||||
const IPAddress ipAddress() const;
|
||||
|
||||
@@ -117,8 +117,19 @@ ReconnectStatus W5500Device::reconnect()
|
||||
{
|
||||
_hasDHCPAddress = true;
|
||||
dhcpRetryCnt = 1000;
|
||||
Log->print(F(" DHCP assigned IP "));
|
||||
Log->println(Ethernet.localIP());
|
||||
if(_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
Log->print(F(" DHCP assigned IP "));
|
||||
Log->println(Ethernet.localIP());
|
||||
}
|
||||
}
|
||||
|
||||
if(!_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
Ethernet.setLocalIP(_ipConfiguration->ipAddress());
|
||||
Ethernet.setSubnetMask(_ipConfiguration->subnet());
|
||||
Ethernet.setGatewayIP(_ipConfiguration->defaultGateway());
|
||||
Ethernet.setDnsServerIP(_ipConfiguration->dnsServer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user