Returning from function that calls System.sleep(SLEEP_MODE_DEEP)

I have a function:

Particle.function(“deepsleep”, deepsleep);

int deepsleep(String seconds)
{
System.sleep(SLEEP_MODE_DEEP, seconds.toInt());
}

But, as one would expect, calling

$ particle function call mydevice deepsleep 3600

errors out, because Photon goes to sleep before it can return.

Is there a way around this, so my client app doesn’t complain?

Use the function to set an unsigned long to millis()+10000 and in your loop run the sleep function once millis() is greater then that variable (and that variable is not 0).

Your device will then sleep 10 seconds after the function is run giving it 10 seconds to correctly send the return from the function.

Perfect, thank you.