Limit automatic power cycles

Hello,

After trying to solve this problem for several days I have decided to try asking here. I feel this should be an easy thing to do, but I can't make it work.

I am trying to use an Arduino Uno with an ethernet shield at a remote site to monitor voltages and data connection. I am using wireless routers for data communications. Sometimes the routers will "hang" and not pass traffic even though they still have a connection. I have the remote wireless router checking the http connection with the main data collection computer located 50 miles away once every 15 minutes. If it does not get a response the Arduino will flip a relay off, wait 15 seconds and then back on again. The problem is, I want to limit the power cycles to four times. This station is repeated through another site and the problem could be at the repeater site so I don't want to keep bouncing my radio over and over until I can get there (this location is approximately 400 miles from my office). I have tried "for" statements (Line 124) and "while" statements but I still haven't been able to get it to stop power cycling, it just seems to ignore it.

Please just point me in the right direction - I want to learn how to fix it myself.

The code is too long to post here so I have included it as an attachment.

Thanks,
John

FYI - If you are wondering, this is for an earthquake monitoring station in East Tennessee.

WMTN2.txt (7.73 KB)

The code you posted does no counting of how many times you have retried. When your checkIfmttnIsAlive() function returns false, increment a variable. If that functions returns true, reset that variable to 0. Add a check to see what value that variable has and if it is less than 4, run checkIfmttnIsAlive() again..

Also, since you are using a Uno, get rid of all your Strings and learn how to use char arrays or you will eventually run into problems since there is not very much memory available.

  if (resetCount < MaxResetCount) {

    if (millis() - lastmttnCheck > 900000)  //Check if there is a connection to mttn every 15 Minutes
    {
      lastmttnCheck = millis();
      Serial.print("Number of times radio reset");
      Serial.println(resetCount);
      if (!checkIfmttnIsAlive())
      {
        Serial.println("Link to mttn is DOWN!");
        digitalWrite(wmtn2ep, HIGH); // If link is down, turn off EP radio
        delay (15000);  // Wait 15 seconds
        digitalWrite(wmtn2ep, LOW);  // Turn radio back on
        resetCount++;
      }
      else {
        resetCount=0;
      }
      delay(1000);
    }
  }

That worked like a charm. Thank you very much. I will take your advice to learn char arrays.