Is - delay(xx) - a blocking call for cloud operations?

Hi…

I am trying to send an event to the cloud, and then wait for 10 seconds to see if the cloud publishes an event back that will affect how the photon behaves. basically it’s a wx report unit. So when the unit wakes up… It connects to the cloud, sends the AOK signal. And I want it to wait for 10 seconds to give the cloud the opportunity to call it and do stuff like setting variables or calling functions… if nothing happens it then goes to sleep again.

I notice that doing delay(xxx) will wait for n ms… But will not listen to cloud publishes events.

Do you know if this is expected?

Thanks

I’m not a 100% sure what the current implementation of delay() does. I know it (used to?) call particle.process() if the delay exceeded some amount of time to make sure the cloud connection didn’t drop. With multithreading, this might no longer be required.
That said, using delay isn’t really that elegant anyway, since you’re basically telling it to do nothing but count to ten, ignoring EVERYTHING else. You might want to look into a millis() implementation, or even use the fancy new software timers we recently got.
Here’s some more information about why delays aren’t all that awesome, and some examples for a millis configuration: http://playground.arduino.cc/Code/AvoidDelay

Thank you.

Do you have more info on the software timers?

simple… this way:

unsigned long startTime = millis();
while(millis() - startTime < 10000UL)
{
  Particle.process();
}

your intent will be quite clear when another programmer sees it (or you come back to it in a year or so!)

1 Like

Sure thing, have a look: https://docs.particle.io/reference/firmware/photon/#software-timers

Although the millis() option might be better suited here, reading up on those timers never hurts :slight_smile: