This has me very confused!
I can run the following example on Arduino IDE for connecting my custom esp32 board with ethernet, and it connects to the test client, google.com, as expected :
#include <ETH.h>
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event) {
switch (event) {
case SYSTEM_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char * host, uint16_t port) {
Serial.println("starting testclient");
Serial.print("\nconnecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
}
void setup() {
Serial.begin(115200);
Serial.println("starting wifi onevent");
WiFi.onEvent(WiFiEvent);
Serial.println("ending wifi onevent");
//ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
Serial.println("starting eth begin");
ETH.begin(0, 2, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO17_OUT);
Serial.println("ending eth begin");
}
void loop() {
Serial.println("starting loop");
if (eth_connected) {
testClient("<website address>", 80);
}
delay(10000);
}
This same code also compiles with no issues in PlatformIO, but after writing to the board it doesn’t connect at all to ethernet.
By adding print statements to debug, I was able to see that it fails with PlatformIO in void loop()
:
if (eth_connected) {
The only thing I can think of is that the platformio.ini file is missing something, or that the ETH library its using is somehow different to the one arduino finds.
Here is my platformio.ino (I have tested that this board type works with my custom board on other projects):
[env:eth]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
build_unflags = -Werror=reorder
Any help would be very appreciated!