khoih-prog / Ethernet_Generic

Simple Ethernet library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, W5100S, W6100. With this library you can use the Arduino Ethernet (shield or board) to connect to Internet to provides both Client and server functionalities.
42 stars 22 forks source link

Ethernet.begin(&MAC) hangs when DHCP is not available #23

Closed CNSNGopenSourceProjects closed 1 year ago

CNSNGopenSourceProjects commented 1 year ago

I am using your library with Generic RP2040 + W5500, connected to 4G modem, using DHCP. I am using Arduino IDE version 2.0.3 on Windows 10 Pro 22H2.

To get the connection, I used Ethernet.begin(&MAC);

Everything was going fine until I tested modem problem. On this tests, I unplug the Ethernet cable, emulating a modem problem, and the begin() never ends. It's looks like the library does not know what to do when it can't access the DHCP.

To confirm the error, I repeated the operation, but using fixed IP Ethernet.begin(&MAC, &IP);. It works fine.

I would like to recommend:

  1. The begin() returns a Boolean informing it fails or not.
  2. The begin() include a timeout or add a new set timeout function for legacy compatibility.

I appreciate your help.

Best regards,

Fernando Camargo mailto: fernando.camargo@conseng.com.br

khoih-prog commented 1 year ago

Hi @CNSNGopenSourceProjects

Check and use accordingly

https://github.com/khoih-prog/Ethernet_Generic/blob/1d5283fff151a2479ad612b7be66a70fb5c41d65/src/Ethernet_Generic.hpp#L229-L232

You have to know how to use the function correctly and in correct use-case.

If Returns 0 if the DHCP configuration failed, call the function with staticIP

https://github.com/khoih-prog/Ethernet_Generic/blob/1d5283fff151a2479ad612b7be66a70fb5c41d65/src/Ethernet_Generic.hpp#L269-L273

The examples are just simple demos to show you basic usage of the functions. You have to read, understand the functions to use in any complex use-case.

Be sure not to write unnecessary issues or they will be deleted / ignored, etc.