mirror of
https://github.com/anklimov/lighthub
synced 2025-12-10 05:39:51 +03:00
printIP, saveIP, loadIP
This commit is contained in:
@@ -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)) {
|
||||||
|
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 {
|
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();
|
||||||
@@ -446,7 +456,8 @@ void onInitialStateInitLAN() {
|
|||||||
resetW5100();
|
resetW5100();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
printIPAddress();
|
Serial.print(F("Got IP address:"));
|
||||||
|
printIPAddress(Ethernet.localIP());
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user