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.
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.
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 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:
@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).