How to properly reset Ethernet connection

I am building a datalogger that will POST data to a website and I would like to design it to run for years.

The way I have it set up is that it resets the W5200 when it fires up. Then resets the connection with this (resetPin is the reset of the the W5200 module):

void resetCon() {
  digitalWrite(resetPin, LOW);
  digitalWrite(resetPin, HIGH);
  #if defined(WIZ550io_WITH_MACADDRESS)
  if (Ethernet.begin() == 0) {
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
#if defined(WIZ550io_WITH_MACADDRESS)
    Ethernet.begin(mac, ip);

This works fine at first. The problem comes when a connection is not made, I call resetCon() again just to make sure that this is not the issue. When I do this, my RAM drops by over 100 each time.

How can I reset the connection without eating up my RAM?


When I do this, my RAM drops by over 100 each time.

Because Ethernet.begin() is failing to free something?

PaulS is right. It obviously isn't freeing or reusing the memory.

However, that is not an Arduino ( library, so I can't offer much help. Maybe a link to the hardware and library you are using might help.

If your sketch client code is written correctly, you shouldn't need to reset the w5200.

I am using the library and WebClient sketch that came with the Arduino IDE v1.0.5 as the base. I found a link to the sketch here gr_ethernet_examples/gr_WebClient.cpp at master · embeddist/gr_ethernet_examples · GitHub

I wrote the resetCon() function to incorporate parts of the sketch. That is not part of any library.

My goal for this sketch is to test Arduino as a remote datalogger that could potentially be installed in thousands of locations and operate for years without human interaction. So if something goes wrong, I want the unit to completely reset itself.

The reason I have the reset in the connection is to act as a 'catch all'. If it loses connection for any reason, it will just reset. That way, even if some strange condition arises, it will eventually correct itself.

For now, I just have it set to monitor the free memory, and if it drops below 250, it times out the watchdog and does a full system reset. Not the most elegant, but at least it should work.

Are you saying that I can drop the reset and it should still function the same?