Arduino Mega2560 + Ethernet Shield + some peripherals.(static internal IP, gateway and DNS configured, no MAC conflict, no IP conflict)Client connects frequently to php script to read and/or set some data.Everything works well but from time to time program stop working. Probably issue is related to internet connection (DSL) when my ISP reset connection.

In loop() my program check every 5 sec data from php script and for some information received call function ~30sec long.

Any suggestions?

How to check outside loop() if program is still working and reset board if time in loop is > 60sec?

If it takes 30 seconds to react to a change, is it even reasonable to check for a change every 5 seconds?You want help with the code you didn't post?

Yes, it is.. check every 5 seconds for command to run 30 sec long task - of course when task is running no reason to read from host. Also to inform host that client is alive (status on website) and responds commands.

Code? Does it really matter? Let say it is typical exampleThe question is how to check if loop() takes more than 60 sec and reset board if so - what inside loop() does not matter...

The only one modification is i check for specific command recived and call function. My function/task works well - never hangs

I did some more test today - there is no problem if I un-plug network cable, it starts well when cable is pluged back..

You can't, easily. You might be able to use a servo and large capacitor. Charge the capacitor, and use it to keep the servo running long enough to rotate through enough motion to lean on the reset switch for long enough.

There are known reasons why all of the W5100 sockets can be blocked (permanently connected).

Surfer Tim has referenced an updated example program that includes a solution for stuck/blocked sockets at:

http://forum.arduino.cc/index.php?topic=277910.0

Basically within your loop() function you need to call another function that checks for, and immediately clears, any blocked/stuck sockets. Otherwise anything that runs Arduino ethernet, especially one exposed to the www world via port forwarding, can get totally blocked to incoming or outgoing connections.

Surfer Tim's example program gives you a procedure called checkSockStatus() that does just that.

I used this code to see how fast loop() runs. Slightly different from what you asked, which was seconds (or part thereof) per loop- mine's the inverse, number of loops per second. But pretty much the same kind of thing.

It does not make any sense.. if program hangs inside the loop() never rich end of the loop..

Quote from: PaulS

You can't, easily. You might be able to use a servo and large capacitor. Charge the capacitor, and use it to keep the servo running long enough to rotate through enough motion to lean on the reset switch for long enough.

Other answers do not really helpStill the same issue - if something happened inside the loop() and program hangs, no chance to check time at the end of the loop()

It is client, so I control when to close connection and flush client..

Well.. I think it could be solved by:

- set timer1 interrupt at 1Hz- every 1 sec add 1 to resetCounter and check value, if > 60 reset board (no servos, no big capacitors, no trained dogs, no need to press button to fully reset the Arduino.)- in loop() having valid respond from the server set resetCounter = 0;

So, if program hangs and/or no answer from server for more than 60sec - reset the board.The compromise is it will reset board if server is down but.. well.. if server is down it doesn't matter if I reset board..

CatweasleNZ made some good points. He was the reason for my latest web server modifications. It now includes a stuck socket fix, but that should not affect the client code.

My example client sketch does fine. However, most example client sketches suffer from failures due to broken connections or stalled servers. That will lock up most client code if there is no timeout feature. Take a look at my client code. Maybe that will give you some ideas on how to prevent a lockup.http://playground.arduino.cc/Code/WebClientExamine the connectLoop variable and how it prevents the lockup you probably suffer from now.