minor ethernet tweaks

This commit is contained in:
arovak 2020-05-08 21:38:24 +02:00
parent 10dd8fbce2
commit 647619f1df
3 changed files with 21 additions and 10 deletions

View File

@ -18,7 +18,7 @@ void ethernetSetup()
Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); Log.notice(F("ETH: Failed to configure Ethernet using DHCP"));
} else { } else {
ip = Ethernet.localIP(); 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, ":")); Log.notice(F("ETH: MAC Address %s"), halGetMacAddress(0, ":"));
@ -33,15 +33,19 @@ void ethernetSetup()
mac[4] = (baseUID & 0x0000FF00) >> 8; mac[4] = (baseUID & 0x0000FF00) >> 8;
mac[5] = (baseUID & 0x000000FF); 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.setCsPin(W5500_CS);
Ethernet.setRstPin(W5500_RST); Ethernet.setRstPin(W5500_RST);
Ethernet.setHostname("HASP"); Ethernet.setHostname(ethHostname);
Log.notice(F("ETH: Begin Ethernet W5500")); Log.notice(F("ETH: Begin Ethernet W5500"));
if(Ethernet.begin(mac) == 0) { if(Ethernet.begin(mac) == 0) {
Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); Log.notice(F("ETH: Failed to configure Ethernet using DHCP"));
} else { } else {
ip = Ethernet.localIP(); 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 #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 #endif

View File

@ -4,4 +4,5 @@
void ethernetSetup(); void ethernetSetup();
void ethernetLoop(void); void ethernetLoop(void);
bool ethernetEvery5Seconds();
#endif #endif

View File

@ -162,13 +162,7 @@ void loop()
#endif #endif
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
#if USE_BUILTIN_ETHERNET > 0 isConnected = ethernetEvery5Seconds();
isConnected = Ethernet.linkStatus() == LinkON;
Serial.print(Ethernet.linkStatus());
#else
isConnected = Ethernet.link() == 1;
Serial.print(Ethernet.link());
#endif
#endif #endif
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0