Skip to content

Commit

Permalink
Bugfix for LAN connection on Olimex EVB
Browse files Browse the repository at this point in the history
  • Loading branch information
fredlcore committed Jun 17, 2024
1 parent effa632 commit 5615700
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions BSB_LAN/BSB_LAN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@
#define BOARD ARDUINO_DUE
#endif

// For some reason, pins_arduino.h for the Olimex EVB does not contain the configuration for the LAN interface (while Olimex POE and POE-ISO do have it), so we have to define them here before including ETH.h.
#if defined(ESP32) && BOARD == ESP32_OLIMEX && !defined(ETH_PHY_TYPE)
#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_ADDR 0
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER -1
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif

#define BUS_OK 1
#define BUS_NOTFREE -1
#define BUS_NOMATCH -2
Expand Down Expand Up @@ -724,7 +734,8 @@ 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);
return ETHClass::begin();

This comment has been minimized.

Copy link
@DE-cr

DE-cr Jun 17, 2024

Contributor

Fyi: This change breaks compilation for "naked" ESP32 (NodeMCU)!

This comment has been minimized.

Copy link
@fredlcore

fredlcore Jun 17, 2024

Author Owner

Thanks, fixed with ba8ba57

// return ETHClass::begin();
return ETHClass::begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE);
}
};

Expand Down Expand Up @@ -7447,7 +7458,7 @@ void startLoggingDevice() {
void createTemporaryAP () {
#if defined (ESP32)
esp_wifi_disconnect(); // W.Bra. 04.03.23 mandatory because of interrupts of AP; replaces WiFi.disconnect(x, y) - no arguments necessary
printlnToDebug(" Setting up AP 'BSB-LAN'");
printlnToDebug("Setting up AP 'BSB-LAN'");
WiFi.softAP("BSB-LAN", "BSB-LPB-PPS-LAN");
IPAddress t = WiFi.softAPIP();
localAP = true;
Expand Down Expand Up @@ -7828,10 +7839,10 @@ void setup() {

printToDebug("Starting network connection via ");
switch (network_type) {
case LAN: printlnToDebug("Ethernet/LAN"); break;
case WLAN: printlnToDebug("WiFi/WLAN"); break;
case LAN: printToDebug("Ethernet/LAN"); break;
case WLAN: printToDebug("WiFi/WLAN"); break;
}
printToDebug("...\r\n");
printlnToDebug("...");
#if defined(ESP32)
WiFi.onEvent(netEvent);
#endif
Expand Down Expand Up @@ -7875,11 +7886,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 @@ -7889,23 +7896,35 @@ void setup() {
}
} else {
if (network_type == LAN) {
#if defined(ESP32)
if (!Ethernet.begin(mac)) createTemporaryAP(); // DHCP
#else
Ethernet.begin(mac); // DHCP
#endif
printToDebug("Waiting for DHCP address");
unsigned long timeout = millis();
while (!Ethernet.localIP() && millis() - timeout < 20000) {
printToDebug(".");
delay(100);
Serial.println(1);
if (Ethernet.begin(mac)) { // DHCP
Serial.println(2);
if (!Ethernet.localIP()) {
Serial.println(3);
printToDebug("Waiting for DHCP address");
unsigned long timeout = millis();
while (!Ethernet.localIP() && millis() - timeout < 20000) {
printToDebug(".");
delay(100);
}
writelnToDebug();
}
}
writelnToDebug();
}
}
#if defined(ESP32)
if (network_type == LAN && !Ethernet.connected()) {
Serial.println(4);
Serial.println(Ethernet.localIP());
createTemporaryAP();
}
#endif
if (network_type == LAN) {
SerialOutput->println(Ethernet.localIP());
SerialOutput->println(Ethernet.subnetMask());
SerialOutput->print("IP: ");
SerialOutput->print(Ethernet.localIP());
SerialOutput->print(" netmask: ");
SerialOutput->print(Ethernet.subnetMask());
SerialOutput->print(" gateway: ");
SerialOutput->println(Ethernet.gatewayIP());
} else {
#if defined(ESP32) || defined(WIFISPI)
Expand Down Expand Up @@ -7960,7 +7979,7 @@ void setup() {
}
#endif

printToDebug("Waiting 3 seconds to give Ethernet shield time to get ready...\r\n");
printlnToDebug("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 5615700

Please sign in to comment.