Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 ETH.h linkUp never reports true #6105

Closed
1 task done
MartinMueller2003 opened this issue Jan 7, 2022 · 11 comments · Fixed by #7593
Closed
1 task done

ESP32 ETH.h linkUp never reports true #6105

MartinMueller2003 opened this issue Jan 7, 2022 · 11 comments · Fixed by #7593
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved

Comments

@MartinMueller2003
Copy link

Board

ESP32 All

Device Description

LoLin D32 Pro. ESP32-CAM, TTGO - all

Hardware Configuration

LAN 8720 Ethernet Adapter

Version

v2.0.1

IDE Name

Arduino 1.8.1

Operating System

ESP32

Flash frequency

1

PSRAM enabled

yes

Upload speed

900k+

Description

ETH.h has no code that ever sets the link up flag to true. This results the linkUp function to always report false even when the link is up and passing data. The link up flag is used when compiled for any ESP32 platform.

Sketch

Example sketch from the repository modified to call ETH.linkUp and print result.

Debug Message

No debug message needed. Code review identified this issue

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@MartinMueller2003 MartinMueller2003 added the Status: Awaiting triage Issue is waiting for triage label Jan 7, 2022
@MartinMueller2003 MartinMueller2003 changed the title ESP32 ETH.h linkUp never reprots true ESP32 ETH.h linkUp never reports true Jan 7, 2022
@TD-er
Copy link
Contributor

TD-er commented Jan 12, 2022

Yep, this is a bug indeed, introduced recently as it used to work just fine.

bool ETHClass::linkUp()
{
#ifdef ESP_IDF_VERSION_MAJOR
return eth_link == ETH_LINK_UP;
#else
return eth_config.phy_check_link();
#endif
}

The enum eth_link is never set other than what the constructor does.

There are other functions which currently lack implementation too, like fullDuplex()

@VojtechBartoska
Copy link
Contributor

Hello, can you please retest this on v2.0.3-rc1?

@VojtechBartoska VojtechBartoska added Area: BT&Wifi BT & Wifi related issues Resolution: Awaiting response Waiting for response of author and removed Status: Awaiting triage Issue is waiting for triage labels Apr 11, 2022
@TD-er
Copy link
Contributor

TD-er commented Apr 11, 2022

Hello, can you please retest this on v2.0.3-rc1?

This also still has the same code as when it was reported:

2.0.3-RC1:

bool ETHClass::linkUp()
{
#ifdef ESP_IDF_VERSION_MAJOR
return eth_link == ETH_LINK_UP;
#else
return eth_config.phy_check_link();
#endif
}

@VojtechBartoska VojtechBartoska removed the Resolution: Awaiting response Waiting for response of author label Apr 11, 2022
@VojtechBartoska
Copy link
Contributor

Adding to the roadmap.

@VojtechBartoska VojtechBartoska added the Status: Needs investigation We need to do some research before taking next steps on this issue label Apr 11, 2022
@DoctorDeatch
Copy link

As I understand it, it has not been repaired to this day?

@TD-er
Copy link
Contributor

TD-er commented Aug 23, 2022

As I understand it, it has not been repaired to this day?

That's correct.
In my software I act on the events.
However this is a bit tricky, because no Ethernet event can be used more than once.
So on a "disconnect" event, I destruct the Eth object and create it again.

It is a seriously hacky fix, but at least it is workable.

@DoctorDeatch
Copy link

I have so far bypassed this problem by using a low-quality pin and connecting it directly to the LEDlink of the network card :)

As I understand it, the same implementation problem does not allow changing the settings from a static address to DHCP, without reinitializing ETH.begin();

@DoctorDeatch
Copy link

As I understand it, it has not been repaired to this day?

That's correct. In my software I act on the events. However this is a bit tricky, because no Ethernet event can be used more than once. So on a "disconnect" event, I destruct the Eth object and create it again.

It is a seriously hacky fix, but at least it is workable.

please tell me what procedure you are performing this?
and also, I can't figure out in any way what type of variable is the value that subnet Mask() returns?

@TD-er
Copy link
Contributor

TD-er commented Aug 24, 2022

Well my code is rather complex and to be honest I hate how complex it has become to overcome all quirks regarding WiFi and now also Ethernet events and things not working how you'd expect them to.
One of the things I did was to make an object to keep track of what states and events I've seen and processed.
For ethernet, this object is EthEventData (in my project, not part of the SDK)

Example of how I keep track of states while establishing a connection:
https://github.com/letscontrolit/ESPEasy/blob/2923ec74a58c0933d337c98eabed0424f70bf294/src/src/ESPEasyCore/ESPEasyEth.cpp#L138-L181

Implementation of my EthLinkUp()
https://github.com/letscontrolit/ESPEasy/blob/2923ec74a58c0933d337c98eabed0424f70bf294/src/src/ESPEasyCore/ESPEasyNetwork.cpp#L241-L252

The subnet mask is also just an IP address:
https://github.com/letscontrolit/ESPEasy/blob/2923ec74a58c0933d337c98eabed0424f70bf294/src/src/ESPEasyCore/ESPEasyNetwork.cpp#L87-L99

@ppescher
Copy link
Contributor

My own quick fix was:

bool ETHClass::fullDuplex()
{
#ifdef ESP_IDF_VERSION_MAJOR
    eth_duplex_t link_duplex;
    esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &link_duplex);
    return (link_duplex == ETH_DUPLEX_FULL);
#else
    return eth_config.phy_get_duplex_mode();
#endif
}

bool ETHClass::linkUp()
{
#ifdef ESP_IDF_VERSION_MAJOR
    return WiFiGenericClass::getStatusBits() & ETH_CONNECTED_BIT;
#else
    return eth_config.phy_check_link();
#endif
}

Not sure if this could be definitive, but it looks good to me, except the #ifdef that should be replaced with the correct version: every other place in ETH.cpp uses #if > 3 but I don't know when those changes have been introduced in the ESP-IDF.

@TD-er
Copy link
Contributor

TD-er commented Dec 13, 2022

Thanks @ppescher
I will try this code to see if it is working.
If so, then it would be great to see it in the main repo.

Repository owner moved this from Todo to Done in Arduino ESP32 Core Project Roadmap Dec 19, 2022
@VojtechBartoska VojtechBartoska added Status: Solved and removed Status: Needs investigation We need to do some research before taking next steps on this issue labels Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved
Projects
5 participants