Skip to content

Commit

Permalink
Improve setup LAN DHCP connection debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Mar 24, 2024
1 parent 1f89830 commit b597268
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions BSB_LAN/BSB_LAN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ public:
bool begin(uint8_t *mac) {
return ETHClass::begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
}
bool connected() {
return WiFiGenericClass::getStatusBits() & ETH_CONNECTED_BIT;
}
};

Eth Ethernet;
Expand Down Expand Up @@ -7173,7 +7176,11 @@ void netEvent(WiFiEvent_t event) {
break;
case ARDUINO_EVENT_ETH_GOT_IP:
SerialOutput->print(PSTR("Ethernet got IP: "));
SerialOutput->println(ETH.localIP());
SerialOutput->print(ETH.localIP());
SerialOutput->print(PSTR(" netmask: "));
SerialOutput->print(ETH.subnetMask());
SerialOutput->print(PSTR(" gateway: "));
SerialOutput->println(ETH.gatewayIP());
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
SerialOutput->println(PSTR("Ethernet disconnected."));
Expand Down Expand Up @@ -7645,10 +7652,10 @@ void setup() {

printToDebug(PSTR("Starting network connection via "));
switch (network_type) {
case LAN: printlnToDebug(PSTR("Ethernet/LAN")); break;
case WLAN: printlnToDebug(PSTR("WiFi/WLAN")); break;
case LAN: printToDebug(PSTR("Ethernet/LAN")); break;
case WLAN: printToDebug(PSTR("WiFi/WLAN")); break;
}
printToDebug(PSTR("...\r\n"));
printlnToDebug(PSTR("..."));
#if defined(ESP32)
WiFi.onEvent(netEvent);
#endif
Expand Down Expand Up @@ -7692,11 +7699,7 @@ void setup() {
dnsserver = IPAddress(ip_addr[0], ip_addr[1], ip_addr[2], 1);
}
if (network_type == LAN) {
#if defined(ESP32)
if (!Ethernet.begin(mac, ip, dnsserver, gateway, subnet)) createTemporaryAP(); //Static IP
#else
Ethernet.begin(mac, ip, dnsserver, gateway, subnet); //Static IP
#endif
} else {
#if defined(ESP32)
WiFi.config(ip, gateway, subnet, dnsserver);
Expand All @@ -7706,23 +7709,30 @@ void setup() {
}
} else {
if (network_type == LAN) {
#if defined(ESP32)
if (!Ethernet.begin(mac)) createTemporaryAP(); // DHCP
#else
Ethernet.begin(mac); // DHCP
#endif
printToDebug(PSTR("Waiting for DHCP address"));
unsigned long timeout = millis();
while (!Ethernet.localIP() && millis() - timeout < 20000) {
printToDebug(PSTR("."));
delay(100);
if (Ethernet.begin(mac)) { // DHCP
if (!Ethernet.localIP()) {
printToDebug(PSTR("Waiting for DHCP address"));
unsigned long timeout = millis();
while (!Ethernet.localIP() && millis() - timeout < 20000) {
printToDebug(PSTR("."));
delay(100);
}
writelnToDebug();
}
}
writelnToDebug();
}
}

#if defined(ESP32)
if (network_type == LAN && !Ethernet.connected()) createTemporaryAP();
#endif

if (network_type == LAN) {
SerialOutput->println(Ethernet.localIP());
SerialOutput->println(Ethernet.subnetMask());
SerialOutput->print(PSTR("IP: "));
SerialOutput->print(Ethernet.localIP());
SerialOutput->print(PSTR(" netmask: "));
SerialOutput->print(Ethernet.subnetMask());
SerialOutput->print(PSTR(" gateway: "));
SerialOutput->println(Ethernet.gatewayIP());
} else {
#if defined(ESP32) || defined(WIFISPI)
Expand Down Expand Up @@ -7777,7 +7787,7 @@ void setup() {
}
#endif

printToDebug(PSTR("Waiting 3 seconds to give Ethernet shield time to get ready...\r\n"));
printlnToDebug(PSTR("Waiting 3 seconds to give Ethernet shield time to get ready..."));
// turn the LED on until Ethernet shield is ready and other initial procedures are over
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)

Expand Down

0 comments on commit b597268

Please sign in to comment.