Ethernet connection to server fails after a while - reset of shield does not help

Hello,
I have a quite complex project, one part of it regularly uploads sensor data to the thingsspeak server. It works fine, but after a 2-3 days the arduino client cannot connect anymore to the server. It happens after 50 - 200 cycles.

I use the Ethernet.h library, and if the error occurs,

int connect_state = client.connect(server, 80);

returns 0 and all following retries fail. The connection is permanently lost then. Therefore I suppose it is not a problem with the server but one on the arduino side.

My hardware: Arduino Mega, Ethernet Shield with W5100 chip and SD writer, nRF24L01+ transceiver, temperature sensors.

used Libraries:

#include <Time.h>       
#include <EEPROM.h>
#include <SD.h>
#include <StreamLib.h>  
#include <MemoryFree.h>
#include <Ethernet.h>
#include <SPI.h>
#include "RF24.h"    
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"

What I tried:

  1. I tried to reset the ethernet shield when the connection failed, by calling again
'Ethernet.begin(mac, myIP);   
delay(1000); '  ....

but connection still fails. It cannot be recovered.

  1. I checked for memory leaks using <MemoryFree.h> library but all is OK.

3 "EthernetClient client; " the client is initialized anew for each connection. I also tried to initialize it only once globally at the start - but it makes no difference.

  1. I do not use dynamic memory allocation or String objects.

Is there a better way to reset and restart the ethernet library ? I thought when the library is restarted, when calling "Ethernet.begin" everything is clean but it does not work.

So far my only idea is to do a hard reset, by upping the reset pin - but I would rather understand what is wrong.
Is the arduino generally not reliable when it runs for a long time ? or is the problem in a library - how to debug this ?. The IDE is not very helpful here. Any hints are welcome.

Thank you very much for your support !!

That doesn't actually reset it, it just initializes some registers. There is a reset command in the WizNet5100, the W5100Class actually implements a softReset() method but the Ethernet library doesn't offer a high level call for that. You may call it directly:

W5100.softReset();

If that works, you probably ran out of sockets. In that case you should post your complete code as the error is in your code. Calling above is just fighting the symptom, it doesn't actually solve your problem.

A memory leak probably would have other symptoms.

Do you explicitly close it?

That's good but most probably not the problem here.

Because it doesn't do what you thought it does.

Is your kitchen responsible if you did a bad meal?

Not impossible but very improbable.

Do you explicitly close it?
Yes, I checked this

How do I call W5100.softReset(); in my sketch ?
the compiler does not accept it ("'W5100' was not declared in this scope")
In the library it is declared private... do I need to rewrite the library ?

I was wrong, Ethernet.begin() indirectly calls W5100.softReset(), so the chip registers are reset if you do that.

Post your code, maybe we'll find the problem.

Currently I am triying to localize the part of the code which causes the error. It seems that it is not in the ethernet / client area - this I did not expect ! As I need longer test runs, it will take a while. I will report my insights then.
Thanks a lot for the support - helped me to start a systematic search !

Hello, a short update, I tried to create a reduced version of my project for upload. (its a good exercise for bug searching...) During this process I changed a setting in the radio function, now it runs without problems longer than ever. I use the "RF24.h" library for 3 x nRF24L01+ nodes, I just changed to radio.enableDynamicPayloads(); I will keep watching.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.