ESP32EVB & Gateway - LAN8710 Arduino disconnects

Started by Gasman, October 01, 2018, 12:16:26 AM

Previous topic - Next topic

Gasman

Hi all,

I have a problem with my ESP32EVB & Gateway Board and the Ethernet Connection. I get ETH started, ETH connected and ETH disconnected immediately.

ETH Started
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
ETH Disconnected


I checked the Pins and afaik they are correct. It's the same with an ESP32 Gateway Board.

/*
    This sketch shows the Ethernet event usage

*/

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


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


LubOlimex

#1
Only three parameters; I think they should be like five.

bool ETHClass::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2)

I think that without DNS you can't expect the board to solve addresses like "google.com".

Probably you need to add DNS as explained here: https://github.com/espressif/arduino-esp32/issues/1762#issuecomment-413913021
Technical support and documentation manager at Olimex

Gasman

#2
Hi, thanks for the answer.

I am aware that without a proper DNS entry in the configuration the hostname cannot be resolved and I also believe that the disconnects are not related to a missing DNS client configuration.

I soldered a LAN8720 to an ESP32 following https://sautter.com/blog/ethernet-on-esp32-using-lan8720/ using #define ETH_CLK_MODE    ETH_CLOCK_GPIO17_OUT and it works absolutely stable.

Any other ideas where the disconnects come from?

I have added the dns #1 and #2 according to the config definition and added a println statement to make sure dns is set:

/*
    This sketch shows the Ethernet event usage

*/

#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");
      Serial.print("DNS:\t\t");
      Serial.println(ETH.dnsIP());
      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, 0, 90), IPAddress(192, 168, 0, 1), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 0, 2), IPAddress(192, 168, 0, 1));
}


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


Error:
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH MAC: 30:AE:A4:1B:C1:FF, IPv4: 192.168.0.90, FULL_DUPLEX, 100Mbps
DNS: 192.168.0.2
ETH Disconnected

LubOlimex

I try the default example without any edits (aka without "ETH.config") and it seems to work here. I tested it both ESP32-EVB and ESP32-GATEWAY.
Technical support and documentation manager at Olimex

Gasman

Can you put the link in here to make sure we are on the same page.

Thanks for your support.

LubOlimex

Technical support and documentation manager at Olimex

Gasman

I can make it work and i can reproduce the error.

1. Upload script via USB (USB power Hub) - "Hard resetting via RTS pin..."
2. Open Serial Monitor. -> Not working - "ETH connected ... ETH disconnected".
3. Reset with button on PCB -> Not working - "ETH connected ... ETH disconnected".
4. unplug the usb cable. wait a few seconds and plug cable back in.

It Works! The total power off makes it work.

I think the LAN8710 is not fully resetted. The LAN8710 has a NRST on Pin 19. From the schema I can see that it is not connected to the reset switch on the board, right?

So when the script is in the loop of "ETH connected ... ETH disconnected" and i short the two pads on the board (PHY_RST1) it starts working. Board get ip adresse from dhcp and all is fine.

I think there is an issue with the reset of the LAN8710 and when i totally unpower the board both ICs (ESP and 8710) are resetted.

LubOlimex

While the reset can be the source of the problem and there is a known issue with the reset button, I wonder why the software works here. What is the revision printed on the board? Can you take a good quality picture of the top of the board, upload it somewhere and give me the link so we can inspect the revision?

It is also interesting if the problem and the solution persist both with the EVB and the GATEWAY.

I am going to test boards from different revisions.
Technical support and documentation manager at Olimex

Gasman

I can confirm that I have the same effect on the ESP32-PoE and the ESP32-Gateway.

Pls. find the pictures of the ESP32-Gateway here https://imgur.com/a/zwv8k1w and for the ESP32-PoE here https://imgur.com/gallery/VEklYqN


LubOlimex

Ok, I have a solid lead what might be the problem! I believe these problems might be caused by outdated version of the ESP32 for Arduino. Probably there is some incompatibility between the demo and the "old" Ethernet-related libraries are causing the issues.

I managed to replicate some of the errors. It happened when I use outdated version of the ESP32 package. So I tried to update it following the instructions at GitHub but it didn't update properly!!! So I had to delete the whole "hardware" directory in /Documents/Arduino and re-did clean installation of the ESP32 part as explained here: https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/windows.md

Here is a comparison picture of how WIFI examples looks in old and new version of the ESP32 package: https://i.imgur.com/3QJttTm.jpg - if this examples are not like the new part, you need to update until they pop-up (or do clean re-install like me).
Technical support and documentation manager at Olimex

Gasman

#10
My Arduino 1.8.5 looks the same as your update esp32 part. Nevertheless, I removed the hardware folder and reinstalled the ESP32 Arduino code from scratch following exactly the steps in the documentation.

I hate to say it, but there is no difference. I install the script and after the soft reset I get the connected / disconnected loop. Only total removal of power or shortage of the PHY_RST1 helps.

When I pull the ethernet plug, upload the script to the ESP, wait a few seconds after the soft reset and plug the ethernet back in, it works. So I still think the 8710 has a certain status when the cable is connected during the upload that causes the script to loop into connected/disconnected.