Code blocked after Particle.connect

Lets see if i can get all this right, this being my first post to the particle community. im working on a simple project that starts the photon is semi-auto mode. while running my code with the WiFi off everything appears to work fine. i want the photon to connect at a set time every night only if certain parameters are met publish data and than turn the WiFi off. the code i have for connecting works, and i can publish, but only on the first try. any attempt after that fails to publish. i can still connect and then disconnect and WiFi off. i believe there is something blocking. i think this because i have a separate button to reconnect so i can re-flash. after i use my re-flash button the photon stays connected fine but my timer counting code doesn’t work. this sound confusing as i write it but i hope the code is easy enough to follow. ive added alot of delays in places that shouldn’t hinder timing and also some code to try to get things working ex (SYSTEM_THREAD(ENABLED)). there’s some Blynk code in there because i was using blynk to test, but now im doing it without the app. if anyone can take a look at what i have a point out my errors seeing as im still new at this…

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

PRODUCT_ID(); // replace by your product ID
PRODUCT_VERSION(1.0); // increment each time you upload to the console

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

//char auth[] = "";
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 CountDown;
int Connect;
int val1;
int val2;

BlynkTimer timer;


void setup() {
    delay(5000);
    //Blynk.begin(auth); 
    CountDown = timer.setInterval(1000, Count);
    Connect = timer.setInterval(30000, Disconnect);
    timer.disable(CountDown);
    timer.disable(Connect);
    pinMode(Switch1, INPUT);
    pinMode(Switch2, INPUT);
    pinMode(LED, OUTPUT);
    digitalWrite(LED , LOW);
}

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 Publish(){
    timer.enable(Connect);
    Particle.connect();
    waitUntil(WiFi.ready);
    delay(100);
    timer.disable(Connect);
    delay(100);
    Particle.process();
    delay(100);
    Particle.publish("Current Run Time", TimeBuffer, PRIVATE, WITH_ACK);
    Sent = 1;
    Disconnect();
}

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



void loop() {
    Blynk.run(); 
    timer.run();
    
val1 = digitalRead(Switch1);
if(val1 == LOW)
{
    Particle.connect();
}

val2 = digitalRead(Switch2);
if(val2 == LOW)
{
    timer.enable(CountDown);
    Ignition = 1;
    
}
else
{
    timer.disable(CountDown);
    Ignition = 0;
    Sent = 0;
}

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

}

One thing you definetly should do: Wrap the Blynk.run() call in a if (WiFi.ready()) { ... } block.

Also waitUntil(WiFi.ready) is not enough, if you want to publish later on. Rather go for waitUntil(Particle.connected) and drop the extra delay() statements.

I have no idea how BlynkTimer copes without WiFi either. Why do you not use a native Software Timer?

thank you sir for the fast reply, i could switch the the native timer, i just had the blynk timer there and it “was” working. before adding the night time connect and publish. i will adjust the code accordingly.

alright, so i adjusted my code to reflect what what @ScruffR suggested however im having the same issue. counts fine when ever the WiFi is off. can only publish the first time after being reset, and cant count if WiFi is on and connected after pressing reconnect button. still have blynk timers, working on switching them to the native timer.