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"));
} 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

View File

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

View File

@ -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