Skip to content

Commit

Permalink
Improve setup LAN DHCP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Mar 23, 2024
1 parent 1f89830 commit 12779b4
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions BSB_LAN/BSB_LAN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down Expand Up @@ -7306,6 +7310,8 @@ void removeTemporaryAP() {
* Ethernet instance
* *************************************************************** */
void setup() {
delay(3000); // W32-ETH01: wait serial connection to establish

#ifdef BtSerial
SerialOutput = &Serial2;
Serial2.begin(115200, SERIAL_8N1); // hardware serial interface #2
Expand Down Expand Up @@ -7645,10 +7651,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 @@ -7707,24 +7713,32 @@ void setup() {
} else {
if (network_type == LAN) {
#if defined(ESP32)
if (!Ethernet.begin(mac)) createTemporaryAP(); // DHCP
if (Ethernet.begin(mac))
#else
Ethernet.begin(mac); // DHCP
if (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.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 (Ethernet.localIP()) {
// Shutdown Wifi
printlnToDebug(PSTR("Shutdown Wifi"));
WiFi.mode(WIFI_OFF);
} else {
createTemporaryAP(); // DHCP
}
#endif
}
}
if (network_type == LAN) {
SerialOutput->println(Ethernet.localIP());
SerialOutput->println(Ethernet.subnetMask());
SerialOutput->println(Ethernet.gatewayIP());
} else {
if (network_type == WLAN) {
#if defined(ESP32) || defined(WIFISPI)
unsigned long timeout;
#ifdef ESP32
Expand Down Expand Up @@ -7777,7 +7791,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 12779b4

Please sign in to comment.