Hi, I’m losing messages sent right before sleep. I see related topics but none recent. What’s the latest?
The doc says: WITH_ACK flag
This flag causes Particle.publish() to return only after receiving an acknowledgement that the published event has been received by the Cloud.
my code:
Particle.publish(“Before sleep”, mainPayload, WITH_ACK);
//delay(500); //Particle.process(); // process queues before sleep
System.sleep(config);
Particle.publish(“After sleep”, mainPayload);
If I use the delay and process, it seems to work most of the time but I’d rather have a deterministic solution and save 500 ms.
I have WITH_ACK but it doesn’t seem to wait like the doc says, I never receive a “before sleep” message at the console. Why not?
Thanks,
Rainer
Checking the result from Particle.publish(), as Armor suggested, should help. The reason is that Particle.publish() is non-blocking if you don’t check the result, which is a Future<bool>. In your case, you want it to block until acknowledged, before initiating sleep.
Solved, that works! If I assign the response to a value, even if the value is not used subsequently, I get the message published before it sleeps; details, details. I’ll keep the send queue in mind for later. For now it’s working. Thanks very much for your quick, and effective, replies!
–Rainer