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:
- 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.
- 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.
- 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 !!