printIP, saveIP, loadIP

This commit is contained in:
livello
2018-06-28 15:47:05 +03:00
parent 407a2af235
commit 973919dc84
2 changed files with 37 additions and 26 deletions

View File

@@ -184,10 +184,9 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
#ifndef __ESP__ #ifndef __ESP__
void printIPAddress() { void printIPAddress(IPAddress ipAddress) {
Serial.print(F("My IP address: "));
for (byte thisByte = 0; thisByte < 4; thisByte++) { for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print(ipAddress[thisByte], DEC);
Serial.print(F(".")); Serial.print(F("."));
} }
Serial.println(); Serial.println();
@@ -295,8 +294,8 @@ lan_status lanLoop() {
break; break;
case DHCP_CHECK_RENEW_OK: case DHCP_CHECK_RENEW_OK:
Serial.println(F("Renewed success")); Serial.println(F("Renewed success. IP address:"));
printIPAddress(); printIPAddress(Ethernet.localIP());
break; break;
case DHCP_CHECK_REBIND_FAIL: case DHCP_CHECK_REBIND_FAIL:
@@ -307,8 +306,8 @@ lan_status lanLoop() {
break; break;
case DHCP_CHECK_REBIND_OK: case DHCP_CHECK_REBIND_OK:
Serial.println(F("Rebind success")); Serial.println(F("Rebind success. IP address:"));
printIPAddress(); printIPAddress(Ethernet.localIP());
break; break;
default: default:
@@ -420,17 +419,28 @@ void onInitialStateInitLAN() {
#else #else
IPAddress ip,dns,gw,mask; IPAddress ip, dns, gw, mask;
int res = 1; int res = 1;
Serial.println(F("Starting lan")); Serial.println(F("Starting lan"));
if (loadFlash(OFFSET_IP, ip)) if (loadFlash(OFFSET_IP, ip)) {
if (loadFlash(OFFSET_DNS, dns)) Serial.print("Loaded from flash IP:");
if (loadFlash(OFFSET_GW, gw)) printIPAddress(ip);
if (loadFlash(OFFSET_MASK, mask)) Ethernet.begin(mac, ip, dns, gw, mask); if (loadFlash(OFFSET_DNS, dns)) {
else Ethernet.begin(mac, ip, dns, gw); Serial.print(" DNS:");
else Ethernet.begin(mac, ip, dns); printIPAddress(dns);
else Ethernet.begin(mac, ip); if (loadFlash(OFFSET_GW, gw)) {
else { Serial.print(" GW:");
printIPAddress(gw);
if (loadFlash(OFFSET_MASK, mask)) {
Serial.print(" MASK:");
printIPAddress(mask);
Ethernet.begin(mac, ip, dns, gw, mask);
} else Ethernet.begin(mac, ip, dns, gw);
} else Ethernet.begin(mac, ip, dns);
} else Ethernet.begin(mac, ip);
}
else {
Serial.print("No IP data found in flash");
wdt_dis(); wdt_dis();
res = Ethernet.begin(mac, 12000); res = Ethernet.begin(mac, 12000);
wdt_en(); wdt_en();
@@ -438,17 +448,18 @@ void onInitialStateInitLAN() {
} }
if (res == 0) { if (res == 0) {
Serial.println(F("Failed to configure Ethernet using DHCP. You can set ip manually!")); Serial.println(F("Failed to configure Ethernet using DHCP. You can set ip manually!"));
Serial.print(F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n")); Serial.print(F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"));
lanStatus = AWAITING_ADDRESS;//-10; lanStatus = AWAITING_ADDRESS;//-10;
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL; nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
#ifdef W5100_RESET_PIN #ifdef W5100_RESET_PIN
resetW5100(); resetW5100();
#endif #endif
} else { } else {
printIPAddress(); Serial.print(F("Got IP address:"));
lanStatus = HAVE_IP_ADDRESS;//1; printIPAddress(Ethernet.localIP());
} lanStatus = HAVE_IP_ADDRESS;//1;
}
#endif #endif

View File

@@ -117,7 +117,7 @@ void mqttCallback(char *topic, byte *payload, unsigned int length);
#ifndef __ESP__ #ifndef __ESP__
void printIPAddress(); void printIPAddress(IPAddress ipAddress);
#endif #endif