The problem is that my program is mixture of suggestions by different users and I do not fully understand what each line does. For example, I don't know about the relationship between the two lines you mentioned.
I got this code:
if(millis() - old_time >= 2000){
if(retry_count < 10){
if(!WiFi.ready()){
WiFi.connect();
retry_count++;
}
else if (!Particle.connected()){
Particle.connect();
retry_count++;
}
}
else{
WiFi.off();
retry_count = 0;
WiFi.on();
}
old_time = millis();
}
from this thread: Starting Spark Core without wifi [SOLVED] - #3 by kennethlimcp
Again I am not sure how it works. My aim is to have the device keep counting even when there is no wifi connection.
Is there a httpclient that works asynchronously and that would keep the counting working even while it is attempting to send an http request?
I will look up interrupts and see if it solves my problem. In the meantime, thanks for pointing me in the right direction.