sstaub / Ethernet3

Ethernet library for Arduino and Ethernetshield2 / WIZ550io / WIZ850io / USR-ES1 with Wiznet W5500 chip
Other
76 stars 34 forks source link

Eliminated dependency on rand() #45

Closed skcole67 closed 2 years ago

skcole67 commented 3 years ago

Hi

After programming a fairly big Arduino Mega 2560 app (55% flash) with Ethernet3 driving an Ethernet 2 Shield, I found my app was crashing when trying to initialize a STATIC connection after failing to initialize a DHCP connection. After more debugging I found my app was crashing without even your code being called. It was simply the existence of the code call that was causing the problem. So it must be some static aspect.

"Traced" through commenting/uncommenting chunks of code, to your use of the random(). I don't think it is your code that is faulty but the underlying rand() function in the Arduino core. Specifically that supplied to ATMEL. I did not have the time to go that deep into the rand() library, so fixed the problem by removing your dependence on the rand() function. My app happens to not need it at all.

Hope by eliminating this dependence others find your library as reliable.

I admit, there may have been something else causing it, but I seriously dug into all parts of my code, and by eliminating rand() from your library, my application is very stable.

There is a bunch of comments around my change which you might want to eliminate before merging.

Thanks for a great library.

SKC

sstaub commented 3 years ago

Sorry, but it seems that is a problem with the Arduino core or your code. I know that the code is ugly because there is no random seed and the IDs are limited to 2000, but at least the code follows the IETF RCF 2131 which says the ID should a random uint32_t.

skcole67 commented 3 years ago

No problem at all. Just thought I would feed it back. Thanks SKC