December 22, 2024, 11:44:17 PM

ESP32-PoE

Started by tomdom, December 09, 2024, 03:05:05 PM

Previous topic - Next topic

tomdom

Hey, I have a problem with my ESP32-Poe, the network in the RJ45 socket does not work, wifi is OK, what do I have wrong?

CODE


#include <Arduino.h>
#include <ETH.h> // Biblioteka do obsługi Ethernet na ESP32

// Ustawienia IP (opcjonalnie)
IPAddress local_ip(192, 168, 27, 201);
IPAddress gateway(192, 168, 27, 15);
IPAddress subnet(255, 255, 255, 0);

void setup() {
  Serial.begin(115200);
 
  // Inicjalizacja połączenia Ethernet
  if (!ETH.begin()) {
    Serial.println("Nie udało się rozpocząć połączenia Ethernet.");
    while (true) {
      delay(1000);
    }
  }

  // Opcjonalnie: ustawienie statycznego IP
  if (!ETH.config(local_ip, gateway, subnet)) {
    Serial.println("Błąd ustawiania statycznego IP");
  }

  // Czekaj na połączenie
  while (!ETH.linkUp()) {
    delay(1000);
    Serial.println("Oczekiwanie na połączenie...");
  }

  Serial.println("Połączenie Ethernet udane.");
 
  // Zmienna IP przydzielone przez DHCP
  Serial.print("Adres IP: ");
  Serial.println(ETH.localIP());
}

void loop() {
  // Możesz dodać kod do obsługi sieci lub połączeń, np. serwera HTTP
};


LubOlimex

Each ESP32-POE is tested empirically here. Quite likely software issue at your side. Probably wrong network configuration in your case (like wrong IP, wrong gateway, unfitting net mask). Try with DHCP instead. If you can't figure it out, let me know:

1. Do you own exactly ESP32-POE or any of the variants? What exactly is written on the box of the product?

2. Did you select Olimex ESP32-POE from the Arduino menu?

3. Did you first test with the default demo from the package - Examples -> Ethernet -> ETH_LAN8720? What are the results?
Technical support and documentation manager at Olimex

tomdom

ESP32 module variant: Olimex ESP32-POE
https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware

I tested for a fixed IP address, and for DHCP. I still have a problem with this. In addition, I noticed that after connecting to a PoE switch, only PoE lights up on the switch as if the network over LAN was not started.

I program with VisualStudio with the PlatformIO plugin, arduino framework

my platformio.ini file

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

I have not tested with the demo version (examples -> ethernet), I will check it and let you know.

LubOlimex

We have own entries in PlatformIO, use esp32-poe (not esp32dev), refer to this:

https://docs.platformio.org/en/latest/boards/espressif32/esp32-poe.html
Technical support and documentation manager at Olimex

tomdom

do you have any code example?

my project still doesn't work

#include <ETH.h>

//Ethernet ready flag
bool eth_connected = false;

// Callback for Ethernet events
void WiFiEvent(WiFiEvent_t event) {
 switch (event) {
 case ARDUINO_EVENT_ETH_START:
 Serial.println("Ethernet started");
 ETH.setHostname("esp32-poe"); // Set hostname
 break;
 case ARDUINO_EVENT_ETH_CONNECTED:
 Serial.println("Ethernet connected");
 break;
 case ARDUINO_EVENT_ETH_GOT_IP:
 eth_connected = true;
 Serial.println("Ethernet got IP");
 Serial.print("IP Address: ");
 Serial.println(ETH.localIP());
 break;
 case ARDUINO_EVENT_ETH_DISCONNECTED:
 eth_connected = false;
 Serial.println("Ethernet disconnected");
 break;
 case ARDUINO_EVENT_ETH_STOP:
 eth_connected = false;
 Serial.println("Ethernet stopped");
 break;
 default:
 break;
 }
}

void setup() {
 Serial.begin(115200);
 delay(1000);

 //Ethernet event registration
 WiFi.onEvent(WiFiEvent);

 //Ethernet initialization
 Serial.println("Starting Ethernet...");
 ETH.begin(
 0, // PHY address (usually 0)
 -1, // PHY power pin missing
 23, // MDC
 18, // MDIO
 ETH_PHY_LAN8720, // PHY type
 ETH_CLOCK_GPIO17_OUT // ETH clock output on GPIO17
);

}

void loop() {
 if (eth_connected) {
 Serial.println("Ethernet is running!");
 } else {
 Serial.println("Waiting for Ethernet...");
 }
 delay(5000);
}

LubOlimex

There is PHY power pin, it is GPIO12.

#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 12

This is the board definition for Arduino:

https://github.com/espressif/arduino-esp32/blob/master/variants/esp32-poe/pins_arduino.h

But we don't use PlatformIO, if you wish tested example try the Arduino one. E.g. this one:

/*
    This sketch shows the Ethernet event usage

*/

// Important to be defined BEFORE including ETH.h for ETH.begin() to work.
// Example RMII LAN8720 (Olimex, etc.)
#ifndef 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

#include <ETH.h>

static bool eth_connected = false;

// WARNING: onEvent is called from a separate FreeRTOS task (thread)!
void onEvent(arduino_event_id_t event) {
  switch (event) {
    case ARDUINO_EVENT_ETH_START:
      Serial.println("ETH Started");
      // The hostname must be set after the interface is started, but needs
      // to be set before DHCP, so set it from the event handler thread.
      ETH.setHostname("esp32-ethernet");
      break;
    case ARDUINO_EVENT_ETH_CONNECTED: Serial.println("ETH Connected"); break;
    case ARDUINO_EVENT_ETH_GOT_IP:
      Serial.println("ETH Got IP");
      Serial.println(ETH);
      eth_connected = true;
      break;
    case ARDUINO_EVENT_ETH_LOST_IP:
      Serial.println("ETH Lost IP");
      eth_connected = false;
      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);

  NetworkClient 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);
  Network.onEvent(onEvent);
  ETH.begin();
}

void loop() {
  if (eth_connected) {
    testClient("google.com", 80);
  }
  delay(10000);
}

It is important that your board is ESP32-POE. If it is ESP32-POE-WROVER pins are different (clock is GPIO0 not GPIO17).
Technical support and documentation manager at Olimex

tomdom

Thank you for shedding light on the subject, the problem has been solved, I am getting IP via DHCP

my code

#include <ETH.h>

void setup() {
    Serial.begin(115200);
    Serial.println("Starting Ethernet...");

    // Zasilanie PHY ustawione na GPIO12
    if (!ETH.begin(
            ETH_PHY_ADDR,       // Adres PHY
            ETH_PHY_POWER,      // GPIO12 jako pin zasilania
            ETH_PHY_MDC,        // MDC na GPIO23
            ETH_PHY_MDIO,       // MDIO na GPIO18
            ETH_PHY_TYPE,       // Typ PHY: LAN8720
            ETH_CLK_MODE        // Tryb zegara: GPIO17 lub GPIO0
    )) {
        Serial.println("ETH.begin failed!");
        while (1);
    }

    Serial.println("Waiting for Ethernet connection...");
    while (!ETH.linkUp()) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("Ethernet connected!");
    Serial.print("IP address: ");
    Serial.println(ETH.localIP());
}

void loop() {
   
}


platformio.ini

[env:esp32-poe]
platform = espressif32
board = esp32-poe
framework = arduino
build_flags =
    -DCORE_DEBUG_LEVEL=5
    -DETH_PHY_ADDR=0
    -DETH_PHY_POWER=12
    -DETH_PHY_MDC=23
    -DETH_PHY_MDIO=18
    -DETH_PHY_TYPE=ETH_PHY_LAN8720
    -DARDUINO_RUNNING_CORE=1
monitor_speed = 115200

LubOlimex

Glad you got it working!
Technical support and documentation manager at Olimex