I copied the Ethernet example from the Olimex side into the Arduino IDE but I get errors. The link that I used is ==>
"arduino-esp32/libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino"
the errors are the following:
C:\Users\bno\Documents\Home_Assistant\arduino_sketch\test\test_met_eth\eth_test\eth_test.ino: In function 'void WiFiEvent(system_event_id_t)':
eth_test:12:10: error: 'ARDUINO_EVENT_ETH_START' was not declared in this scope
case ARDUINO_EVENT_ETH_START:
^
eth_test:17:10: error: 'ARDUINO_EVENT_ETH_CONNECTED' was not declared in this scope
case ARDUINO_EVENT_ETH_CONNECTED:
^
eth_test:20:10: error: 'ARDUINO_EVENT_ETH_GOT_IP' was not declared in this scope
case ARDUINO_EVENT_ETH_GOT_IP:
^
eth_test:33:10: error: 'ARDUINO_EVENT_ETH_DISCONNECTED' was not declared in this scope
case ARDUINO_EVENT_ETH_DISCONNECTED:
^
eth_test:37:10: error: 'ARDUINO_EVENT_ETH_STOP' was not declared in this scope
case ARDUINO_EVENT_ETH_STOP:
^
exit status 1
'ARDUINO_EVENT_ETH_START' was not declared in this scope
I have copied the code below to show ==>
/*
This sketch shows the Ethernet event usage
*/
#include <ETH.h>
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case ARDUINO_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 ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char * host, uint16_t port)
{
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);
WiFi.onEvent(WiFiEvent);
ETH.begin();
}
void loop()
{
if (eth_connected) {
testClient("google.com", 80);
}
delay(10000);
}
Can you point me where exactly did you download this example from? Which page exactly contains the link to download it?
Meanwhile check this document: https://www.olimex.com/Products/IoT/ESP32/_resources/Arudino-ESP32.txt
Dear LubOlimex,
Thanks for the fast reply.
Apparently I got the software from the Arduino site.
I used the link you advised me and I saw the following difference in
the software.
The enumeration in the events are different:
SYSTEM_EVENT_ETH_START:
SYSTEM_EVENT_ETH_CONNECTED:
.....
.....
In the software I used, it was
ARDUINO_EVENT_ETH_START:
ARDUINO_EVENT_ETH_CONNECTED:
.....
.....
I changed all "ARDUINO" with "SYSTEM" and everything works fine.
Again, thanks for the fast and good support.
Bart.
Quote from: Bart_123 on February 21, 2022, 05:11:29 PMDear LubOlimex,
Thanks for the fast reply.
Apparently I got the software from the Arduino site.
I used the link you advised me and I saw the following difference in
the software.
The enumeration in the events are different:
SYSTEM_EVENT_ETH_START:
SYSTEM_EVENT_ETH_CONNECTED:
.....
.....
In the software I used, it was
ARDUINO_EVENT_ETH_START:
ARDUINO_EVENT_ETH_CONNECTED:
.....
.....
I changed all "ARDUINO" with "SYSTEM" and everything works fine.
Again, thanks for the fast and good support.
Bart.
For anyone else - yes the example needs updating not your framework. This changed in 2021.
Example should be:
void WiFiEvent(WiFiEvent_t event)
{
//debug.println("info: WiFiEvent Received");
switch (event)
{
case ARDUINO_EVENT_ETH_START:
debug.println("ETH Started");
// set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
debug.println("ETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
debug.print("ETH MAC: ");
debug.print(ETH.macAddress());
debug.print(", IPv4: ");
debug.print(ETH.localIP());
if (ETH.fullDuplex())
{
debug.print(", FULL_DUPLEX");
}
debug.print(", ");
debug.print(ETH.linkSpeed());
debug.println("Mbps");
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
debug.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
debug.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
Quote from: Drjaymz on November 11, 2022, 07:00:22 PM......
Hero! Wasted 3 hours of my live trying to figure out why a new POE-ISO board with example code did not work.