ESP 32 POE ISO ethernet not work

Started by MicBar, September 10, 2021, 09:14:52 PM

Previous topic - Next topic

MicBar

Hi,

i'm new on Arduino community and I've been working on ESP32 poe iso for a few days

i want established an ethernet connection between the board and my pc to create a tcp/ip connection between my pc and the board. i tried to use this code



#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12

#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.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();
  ETH.config(IPAddress(192, 168, 1, 101),IPAddress(192, 168, 1, 1),IPAddress(255, 255, 255, 0),IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1));
}


void loop()
{
 
  Serial.print("Looping.. ");
  Serial.print("IPv4: ");
  Serial.println(ETH.localIP());
  if (eth_connected) {
    testClient("google.com", 80);
  }
  delay(10000);
}

but after the flash, from the serial plotter i can see only

Looping.. IPv4: 0.0.0.0

why does ethernet connection not work?

how can i set a static IP and then ping it by command prompt line? i'm using win 10

best regards

LubOlimex

It has static IP address set and maybe it doesn't belong to your network. Try to fiddle with this part:

ETH.config(IPAddress(192, 168, 1, 101),IPAddress(192, 168, 1, 1),IPAddress(255, 255, 255, 0),IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1));

Try with DCHP instead, maybe try this demo:

https://raw.githubusercontent.com/OLIMEX/ESP32-POE/master/SOFTWARE/ARDUINO/ESP32_PoE_Ethernet_SD_Card_Arduino/ESP32_PoE_Ethernet_SD_Card_Arduino.ino

Technical support and documentation manager at Olimex

SejnyM

I don't see something like this:

#define ETH_ADDR 0
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_POWER 5
#define ETH_MDC 23
#define ETH_MDIO 18
#define ETH_CLK ETH_CLOCK_GPIO17_OUT

ETH.begin(ETH_ADDR, ETH_POWER, ETH_MDC, ETH_MDIO, ETH_TYPE, ETH_CLK);