Cant get timers working

having problems with my project, cant get timers to work. i had this bit of code mostly working while using blynk timer. trying to move away from using blynk. may have been causing my Particle.publish to be blocked… but system timers wont work. no sure where ive gone wrong. any pointer would be great! also do i need SYSTEM_THREAD(ENABLED);?

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

char TimeBuffer[100];
int SEC = 0;
int MIN = 0;
int HRS = 0;
int Button;
int LED = D7;
int Switch1 = D1;
int Switch2 = D2;
boolean ButtonState = 0;
boolean Ignition = 0;
boolean Sent = 1;
int val1;
int val2;

Timer CountDown(1000, Count);
Timer Connect(30000, Disconnect);


void Count() {

    ++SEC;
   

    if(SEC == 60)
    {
        ++MIN;
        SEC = 0;
        
    }
    if(MIN == 59 && SEC == 59)
    {
        ++HRS;
        SEC = 0;
        MIN = 0;
    }

     sprintf(TimeBuffer, "Timer %d:%d:%d", HRS, MIN, SEC );
     digitalWrite(LED, HIGH);
     delay(100);
     digitalWrite(LED, LOW);
     
}

void setup() {
    
    delay(5000);
    pinMode(Switch1, INPUT);
    pinMode(Switch2, INPUT);
    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);
}


void Publish(){
    Connect.start();
    Particle.connect();
    waitUntil(Particle.connected);
    Connect.stop();
    Particle.process();
    Particle.publish("Current Run Time", TimeBuffer, PRIVATE, WITH_ACK);
    Sent = 1;
    Disconnect();
}


void Disconnect()
{
    delay(1000);
    Particle.disconnect();
    delay(1000);
    WiFi.off();
}



void loop() {

    val1 = digitalRead(Switch1);
    if(val1 == LOW)
    {
        Particle.connect();
    }

    val2 = digitalRead(Switch2);
    if(val2 == LOW)
    {
        CountDown.start();
        Ignition = 1;
        Sent = 0;
    }
    else
    {
        CountDown.stop();
        Ignition = 0;
    }

    if((Time.hour() >= 18) && (Ignition == 0) && (Sent == 0))
    {
        Publish();
    }


}

Hmm, why would you want to lose one second each hour?
IMO, you are resetting the second and minute one second too early.

Also, have you considered using the Time object - which is working with the onbord RTC - instead? This would rid you of the need for a less precise 1000ms timer.

Next, are you working on an arbitrary time base or do you intend to work with real world (UTC based) times?

For HW questions, have you got external pull-up resistors for your switches? These (or INPUT_PULLUP) is required to prevent open pins from floating.

To remove the need for the second timer, you may want to exchange waitUntil(Particle.connected) and rather use this

void Publish() {
    Particle.connect();
    if (waitFor(Particle.connected, 30000)) {
      Particle.publish("Current Run Time", TimeBuffer, PRIVATE, WITH_ACK);
      delay(5000);  // for system version < 0.7.0 in WiFi devices
      Sent = true;
    }
    Particle.disconnect();
    delay(1000);
    WiFi.off();
}

I'm also confused about this

While you hold the switch LOW you will restart the CountDown timer (which actually counts up) every time loop() comes round, and as soon you let the switch go HIGH again you stop the timer again.
So in neither case it's likely that the timer will ever actually get the chance to fire.

@ScruffR i am aware i will be loosing one sec every hour. when i had the hour add and reset the min to 0 the hour would switch and the min would continue on to 60. so i figured i would sacrifice 1 sec per hour.

i have considered using the RTC but for this project im looking to track on time of a switch to ~250hr and maybe 500 in another case. from reading about the RTC it will over flow after ~49 days of being on and my “switch on” time i expect wont reach 250 hours for close to 60 days, and longer of course if i count to 500.

i am using external pull ups on both switches

as for my “CountDown” thats just how i labeled it. i dont understand why the timer wouldnt get called, unless you mean its getting called every system loop so it never gets a chance to count to 1000ms? and do the function at the end.

RTC (real time clock) will not overflow till January 2038. What you are refering to is the millis() counter :wink:

The answer is here

And in the link behind the blue word "restart".