Particle.publish() Timeout

Hi fellow members.
I have a question about Particle.Publish(). I tried to use it with

waitFor(Particle.publish, 5000);

and it seems not admitted.
There’s a way to timeout Particle.Publish() when no internet is available? For my
measurements it seems to timeout at 20 seconds, but that’s a lot to wait for me.

Thank you for your time.


I could be mistaken but I believe Particle.publish() returns false when the internet is not connected. Additionally, I believe if you use system threading then Particle.publish() is non-blocking. Give that a try.

Also, I’m pretty sure that it’s a valid syntax as it is. You might want to double check that. Other than that, @harrisonhjones’ suggestions hold true.

Thank you, dear Harrison for your help.

System Thread is enabled, and Particle.Publish() is not blocking my code…kind of…it timeout
eventually but it takes 20 seconds to do so.

Check if it returns false also takes 20 seconds until it respond.


Dear Jordy,
Thank you for your reply.

I doesn’t seem to be right. Maybe it cannot be used or need a correct keyword.
Like in Particle.connect(), that use Particle.connected to check for success.


I cannot saw anything useful after looking at spark_wiring_system.h


HI @gavpret

I think the part you are missing in both of these cases is that parenthesis in C/C++ is the function call operator, so there is a big different between waitUntil(Particle.connected)' that you wrote and the correct version:


Hi Brian.

Curiously, I’m using it in my code and it seems to work correctly. It was not my idea, I got the tip
from @ScruffR.


@bko, the syntax without parentheses is correct. waitUntil() and waitFor() don’t actually call the functions passed as parameter (the same as Particle.function() doesn’t call the function but only registers it).

@Moors7 & @gavpret, Particle.publish() is no suitable function to wait for/until. waitFor() and waitUntil() are only meant for functions that create a system events but Particle.publish() does not.
In order to wait for Particle.publish() to succeede you’d need to keep calling it in a loop till it returns true - and as said waitFor()/waitUntil() don’t call the function at all.

But AFAIK there is no way to know whether a publish has already delivered the event or not other than self-subscribing to that event.

Actually you should (at least had to) check for connection before publishing, since the a return value of true will still not be a guarantee that the actual publishing was successful (only that it was successfully queued).


Thank you very much for such detailed explanation. I really appreciate it.