Skip to content

Commit 4730822

Browse files
committed
Add network link status monitoring and IP display
Introduces periodic checks for Ethernet link state changes, printing network details when the link is established and a warning when lost. Also updates the default configuration to use DHCP instead of a static IP for easier deployment.
1 parent 1bc3c77 commit 4730822

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

TankAlarm-112025-Server-BluesOpta/TankAlarm-112025-Server-BluesOpta.ino

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ static double gNextViewerSummaryEpoch = 0.0;
222222
static double gLastViewerSummaryEpoch = 0.0;
223223

224224
static unsigned long gLastPollMillis = 0;
225+
static unsigned long gLastLinkCheckMillis = 0;
226+
static bool gLastLinkState = false;
225227

226228
// Email rate limiting
227229
static double gLastDailyEmailSentEpoch = 0.0;
@@ -2605,6 +2607,14 @@ void setup() {
26052607
#endif
26062608

26072609
Serial.println(F("Server setup complete"));
2610+
Serial.println(F("----------------------------------"));
2611+
Serial.print(F("Local IP Address: "));
2612+
Serial.println(Ethernet.localIP());
2613+
Serial.print(F("Gateway: "));
2614+
Serial.println(Ethernet.gatewayIP());
2615+
Serial.print(F("Subnet Mask: "));
2616+
Serial.println(Ethernet.subnetMask());
2617+
Serial.println(F("----------------------------------"));
26082618
}
26092619

26102620
void loop() {
@@ -2616,6 +2626,29 @@ void loop() {
26162626
// Maintain DHCP lease and check link status
26172627
Ethernet.maintain();
26182628

2629+
// Check for link state changes and display IP when link comes up
2630+
unsigned long now = millis();
2631+
if (now - gLastLinkCheckMillis > 5000UL) {
2632+
gLastLinkCheckMillis = now;
2633+
bool linkUp = (Ethernet.linkStatus() == LinkON);
2634+
if (linkUp && !gLastLinkState) {
2635+
// Link just came up
2636+
Serial.println(F("----------------------------------"));
2637+
Serial.println(F("Network link established!"));
2638+
Serial.print(F("Local IP Address: "));
2639+
Serial.println(Ethernet.localIP());
2640+
Serial.print(F("Gateway: "));
2641+
Serial.println(Ethernet.gatewayIP());
2642+
Serial.print(F("Subnet Mask: "));
2643+
Serial.println(Ethernet.subnetMask());
2644+
Serial.println(F("----------------------------------"));
2645+
} else if (!linkUp && gLastLinkState) {
2646+
// Link just went down
2647+
Serial.println(F("WARNING: Network link lost!"));
2648+
}
2649+
gLastLinkState = linkUp;
2650+
}
2651+
26192652
handleWebRequests();
26202653

26212654
unsigned long now = millis();
@@ -2677,7 +2710,7 @@ static void createDefaultConfig(ServerConfig &cfg) {
26772710
cfg.dailyHour = DAILY_EMAIL_HOUR_DEFAULT;
26782711
cfg.dailyMinute = DAILY_EMAIL_MINUTE_DEFAULT;
26792712
cfg.webRefreshSeconds = 21600;
2680-
cfg.useStaticIp = true;
2713+
cfg.useStaticIp = false; // Use DHCP by default for easier deployment
26812714
cfg.smsOnHigh = true;
26822715
cfg.smsOnLow = true;
26832716
cfg.smsOnClear = false;

0 commit comments

Comments
 (0)