From 1e31c5bf8c3fcc7fc0c836a7ba021d560ee37a88 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Sat, 23 Mar 2024 18:04:05 +0100 Subject: [PATCH] Improve setup LAN DHCP connection debug --- BSB_LAN/BSB_LAN.ino | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/BSB_LAN/BSB_LAN.ino b/BSB_LAN/BSB_LAN.ino index f87f8b61..afc5e2cb 100644 --- a/BSB_LAN/BSB_LAN.ino +++ b/BSB_LAN/BSB_LAN.ino @@ -7173,7 +7173,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.")); @@ -7645,10 +7649,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 @@ -7692,11 +7696,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); @@ -7706,23 +7706,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.localIP()) 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) @@ -7777,7 +7784,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)