From 647619f1df40f9c8f8f8f4d2f740d7c22c0a6eae Mon Sep 17 00:00:00 2001 From: arovak Date: Fri, 8 May 2020 21:38:24 +0200 Subject: [PATCH] minor ethernet tweaks --- src/hasp_ethernet.cpp | 22 +++++++++++++++++++--- src/hasp_ethernet.h | 1 + src/main.cpp | 8 +------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp index f6c1d694..d6f82bff 100644 --- a/src/hasp_ethernet.cpp +++ b/src/hasp_ethernet.cpp @@ -18,7 +18,7 @@ void ethernetSetup() Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); } else { ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(F("ETH: DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } Log.notice(F("ETH: MAC Address %s"), halGetMacAddress(0, ":")); @@ -33,15 +33,19 @@ void ethernetSetup() mac[4] = (baseUID & 0x0000FF00) >> 8; mac[5] = (baseUID & 0x000000FF); + char ethHostname[12]; + memset(ethHostname, 0 ,sizeof(ethHostname)); + snprintf(ethHostname, sizeof(ethHostname), PSTR("HASP-%02x%02x%02x"), mac[3], mac[4], mac[5]); + Ethernet.setCsPin(W5500_CS); Ethernet.setRstPin(W5500_RST); - Ethernet.setHostname("HASP"); + Ethernet.setHostname(ethHostname); Log.notice(F("ETH: Begin Ethernet W5500")); if(Ethernet.begin(mac) == 0) { Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); } else { ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + Log.notice(F("ETH: DHCP Success got IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } #endif } @@ -77,4 +81,16 @@ void ethernetLoop(void) } } +bool ethernetEvery5Seconds() +{ + bool state; +#if USE_BUILTIN_ETHERNET > 0 + state = Ethernet.linkStatus() == LinkON; +#else + state = Ethernet.link() == 1; +#endif + Log.warning(F("ETH: %s"), state ? F("ONLINE") : F("OFFLINE")); + return state; +} + #endif \ No newline at end of file diff --git a/src/hasp_ethernet.h b/src/hasp_ethernet.h index 0b2b6947..177f0908 100644 --- a/src/hasp_ethernet.h +++ b/src/hasp_ethernet.h @@ -4,4 +4,5 @@ void ethernetSetup(); void ethernetLoop(void); +bool ethernetEvery5Seconds(); #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 229159a8..e03e3c21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,13 +162,7 @@ void loop() #endif #if HASP_USE_ETHERNET > 0 -#if USE_BUILTIN_ETHERNET > 0 - isConnected = Ethernet.linkStatus() == LinkON; - Serial.print(Ethernet.linkStatus()); -#else - isConnected = Ethernet.link() == 1; - Serial.print(Ethernet.link()); -#endif + isConnected = ethernetEvery5Seconds(); #endif #if HASP_USE_HTTP > 0