Wait for ACK after NO_ACK publish

Hi Everyone,

I was wondering if it’s possible to wait for the ACK even if publishing with the NO_ACK flag set.
As far as I can tell the ACK is received by the electron even after publishing with NO_ACK set - the difference being that the particle.publish command does not block waiting for the ACK.

What I would like to do is send the data and then wait for the ACK afterwards:

Particle.publish(webhook, TX_DATA, PRIVATE, NO_ACK);
time = millis();
while (time < 20000) 
   //wait for ACK here
   time = millis(); 


This would allow me to check other parameters while still being sure my data reached the cloud.


NO_ACK really does not send an ACK from the cloud, saving 61 bytes of data.

There’s a log of it here showing there is no data sent from the cloud to the device.


Oh sorry, thanks. I must have misread another post.

Is there any way to do a non-blocking WITH_ACK publish?

There is no public version of Particle.publish that allows for checking for success/failure and is non-blocking.

Fortunately, at least in 0.7.0 and later, the insides are actually asynchronous and thus I was able to build a handy class to enable asynchronous callback functions for publish!


Use the following. Keep in mind that a WITH_ACK publish can actually take a lot longer than 20 seconds to complete in situations where the cloud connection may have died.

auto ok = Particle.publish(webhook, TX_DATA, PRIVATE, WITH_ACK);
uint32_t t0 = millis();
while(!ok.isDone() && (millis() - t0) < 20000)
    // you can do something else here or just go on with your normal processing
    // and check back in occasionally

Log.info("publish %s", ok.isSucceeded() ? "succeeded" : "failed");

Thanks joel,

I went for this option because it was so lightweight and easy to add into my current code. seems to be working great.