Watchdog System for Arduino GSM

Complete code below...

Result is...

failed toggles between on and off approx. every second. GSM shield appears to be resetting at same interval.

// libraries

#include <GSM.h>
#include <Arduino.h>
#include <avr/wdt.h>

#define PINNUMBER ""


// initialize the library instance

GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSMVoiceCall vcs;

// Set the Constants

const int buttonPin = 4;     // the number of the PUSHBUTTON PIN
const int readyPin = 13;     // the number of the OK LED PIN
const int failPin = 12;      // the number of the FAIL LED PIN
const int callPin = 11;      // the number of the CALL LED PIN
const int testPin = 8;       // the number of the TEST LED PIN      

// Set the variables

int buttonState = 0;         // variable for reading the pushbutton status

// Timeout Variables

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 21600000; // reset every 6 hours once running.
const unsigned long startupPeriod = 30000; // reset if failed startup process after 30 seconds


void setup() {
  Serial.begin( 115200 ) ;
  Serial.println ("starting . . . ") ;
  
  wdt_disable();     //v2
  delay(2L * 1000L); //v2
  wdt_enable(WDTO_2S); //v2


  startMillis = millis();
  
// initialize the LED pins as an output

  pinMode(readyPin, OUTPUT);  
  pinMode(failPin, OUTPUT);
  pinMode(callPin, OUTPUT);
  pinMode(testPin, OUTPUT);
 
        
// initialize the pushbutton pin as an input

  pinMode(buttonPin, INPUT);

// connection state

  boolean notConnected = true;
  
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
  
  while(notConnected==true){
    
   digitalWrite(failPin, HIGH);

        
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    
   {  notConnected = false;
      digitalWrite(failPin, LOW);
      digitalWrite(readyPin, HIGH);
   }
      

  currentMillis = millis();
  static unsigned long lastResetAtMs = 0 ;
  
    
        if (currentMillis - startMillis >= startupPeriod) {
          
        }
        else if ( currentMillis - lastResetAtMs > 1000 ) {  // v2
      wdt_reset(); // v2  - reset wdt every 1 second until startupPeriod expires
      lastResetAtMs += 1000 ; // v2
      Serial.println("waiting one more second") ;
      
    }

  }
  wdt_disable();     //v2
}



      
                   

  
 
void loop() {
  
  // put your main code here, to run repeatedly
   Serial.println("now in loop") ;
  delay( 1000 ) ;
 
 buttonState = digitalRead(buttonPin);

digitalWrite(readyPin, HIGH);

 if ((buttonState == HIGH)&(vcs.getvoiceCallStatus()!=TALKING))

 {
  digitalWrite(callPin, HIGH);
  vcs.voiceCall("07432297183");
 }

if (vcs.getvoiceCallStatus()==TALKING)
{
digitalWrite(callPin, HIGH);
}
else
{ 
digitalWrite(callPin, LOW);
}

currentMillis = millis();

if (currentMillis - startMillis >= period)

digitalWrite(testPin, LOW);
}

Serial monitor shows this...

starting . . . 
⸮⸮⸮⸮⸮⸮⸮⸮-⸮S⸮S⸮⸮⸮⸮⸮W⸮⸮⸮TV⸮⸮⸮⸮W⸮⸮⸮⸮⸮S⸮⸮⸮⸮⸮S⸮TT⸮⸮.⸮5V⸮R⸮*⸮⸮⸮⸮⸮T⸮⸮⸮⸮