Go Down

Topic: Ethernet shield hangs (Read 1 time) previous topic - next topic

peep rada

I have funny problem with ethernet shield. I am using version 21 software. Duemillanove and official ethernet shield with W5100.

My Arduino controls my remote station electric energy production and usage. And it sends data as statistics to pachube (www.pachube.com/feeds/7458) and from webserver it checks if there are configuration changes, and adjusts its RTC time with NTP.
It is designed to work without internet. If ethernet is disconnected it is no problem. But now problem comes. If there are problems with internet further away from local router, that causes no response from webserver or other services, connection making hangs for too long before shield returns "no connection". This again causes Watchdog to reset the whole system, which again causes loss of power in the whole system. So every time lights go out I know there is no internet again :)
So, question is how to make timeout happen faster?

Of the working principle and saving power, ethernet shield is switched off if not used. Every time it is powered up, waited until it resets properly and then initialised for every usege. So there can not be multiple connection problem. And it hangs on connect();

Any hints?
Code is magic of thinking

peep rada

I've seen that there was a problem with too lenghty delay before recognizing connection fail. It was possible to make that time out shorter by modifying library only I can't find it anymore. Could anyone give some hints?
Code is magic of thinking


Sep 11, 2011, 01:13 pm Last Edit: Sep 11, 2011, 01:38 pm by SurferTim Reason: 1
The timeout is controlled by the W5100 chip. I discovered you can change that timeout retry count and cut the timeout delay in half. You might want to play with that number. I have not tried a value less than 4.

This is in

I added a line in the init() function to shorten the timeout delay. The default retry count is 8. This sets that to 4.
Look for the "//Tim added" comment.

Code: [Select]
void W5100Class::init(void)


// Tim added
 for (int i=0; i<MAX_SOCK_NUM; i++) {

If you try a number smaller than 4, please let me know how it worked.

peep rada

Thanx! It seems it worked. I set the retry count to 1. In that system it is not reasonable to frantically try to connect at any cost. Nothing serious happen if connection fails.

I will monitor how it works and if there are something interesting to report, I'll let you know.
Code is magic of thinking


Sep 16, 2011, 02:19 pm Last Edit: Sep 16, 2011, 02:29 pm by SurferTim Reason: 1
Thanks, peep rada!  :)

I am about to need that in a few days, and it is good to know it works with 1. That is what I will need. One try, then back. I'll determine when it tries again.

Edit: I might be incorrect about the count. That register is a "retry" count. So setting that to '1' may try the connection twice. Maybe when I try the code in a few days, I will try setting that to '0'.  :smiley-eek:

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131