Skip to content

Ethernet.begin() does not return under certian circumstances #4

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

Closed
pulli7 opened this issue Sep 22, 2017 · 9 comments
Closed

Ethernet.begin() does not return under certian circumstances #4

pulli7 opened this issue Sep 22, 2017 · 9 comments

Comments

@pulli7
Copy link

pulli7 commented Sep 22, 2017

In the past, with the Arduino-Ethernet-Shield, I used the following code to wait for ethernet connection to get available, so that I can have at least some limited functionality when ethernet is not available at this time, and automatically jump to full functionality as soon as link gets available.

void setup()
{
  if (Ethernet.begin(mac) == 0)
  {
    FallBackMode();
  } 
}
void FallBackMode()
{
  int Timestamp = millis();
  while(1)
  {
     if ( millis() - Timestamp > 300000)  //try reconnect every 5min
     {
       if (Ethernet.begin(mac, 30000) != 0)  //Problem here
       {                                   
         break;  //successfully connected
       }
       Timestamp = millis();
    }
    //call  "offline application"  here, which serves all functionality that does not need Ethernet
  }//ENDwhile
}

With the Nucleo 429ZI this does not work. As long as the cable is unplugged everthing is fine, but as soon as it is plugged in and ethernet gets available, the program gets locked inside the Ethernet.begin() function and never returns.

Am I misusing the function and it worked just coincidentally with the standard ethernet-shield, or is this a bug?
If this usage of the begin() function is not intended, is there another way to achieve that the board tries reconnecting itself?

@fpistm fpistm assigned ghost Sep 22, 2017
@ghost ghost added the bug label Sep 26, 2017
@ghost
Copy link

ghost commented Sep 26, 2017

Issue reproduced. This is under investigation.

@fpistm
Copy link
Member

fpistm commented Oct 18, 2017

Hi all,
maybe the PR #5 fix this issue as the Ethernet scheduler is called by timer every 1ms?

@pulli7
Copy link
Author

pulli7 commented Oct 18, 2017

Gave it a quick try:

Looks like it changes the behavior in the way, that now calling Ethernet.begin() a second time, after the first try failed, always locks the program inside the function, no matter if ethernet is still unavailable or not.

@ghost ghost mentioned this issue Oct 19, 2017
@ghost
Copy link

ghost commented Oct 19, 2017

@pulli7
Could you try the PR #5? It fixes your issue when several call of begin().

@pulli7
Copy link
Author

pulli7 commented Oct 20, 2017

Confirmed, issue is fixed.
Thank you again @fprwi6labs !

@ghost
Copy link

ghost commented Oct 20, 2017

You're welcome @pulli7 .
@fpistm you can close all those issues.

fpistm added a commit that referenced this issue Oct 20, 2017
@fpistm
Copy link
Member

fpistm commented Oct 20, 2017

Thanks guy.

@fpistm fpistm closed this as completed Oct 20, 2017
@bertoruiz
Copy link

bertoruiz commented Apr 25, 2018

I'm having the same problem with my Arduino UNO and ethernet shield. How exactly do I fix the problem when it hangs?

Examples of hanging:

  • If I turn ON or reset the arduino and I am not connected via CAT5 to a good DHCP source.
  • If arduino is working fine with IP and then if I pull the CAT5(do not reconnect it), but then reset the Arduino and then after it is fully restarted, I then insert the CAT5 from a good DHCP source.
  • If the arduino is already running without it being connected to a good DHCP source, and I then I connect the arduino ethernet shield to a good DHCP source.

It works fine when:

  • I am connected to a good DHCP source prior to turning ON arduino and get an IP right away.
  • I am connected to a good DHCP source prior to RESETING arduino and get an IP right away.

@fpistm
Copy link
Member

fpistm commented Apr 25, 2018

This library is designed for STM32 boards with native Ethernet.
You should submit your issue on https://github.com/adafruit/Ethernet2 or https://github.com/arduino/Arduino/tree/master/libraries/Ethernet depending of your shield.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants