bool success;
success = Particle.publish("motion-detected");
if (!success) {
// get here if event publish did not work
}
in order to detect a suden internet interruption while sending data, I found that the new WITH ACK flag
is able to instantly discover the problem, which is great.
However, I seems that it doesn’t have a timeout and waits forever for the confirmation of success.
There’s a way to timeout it in order to regain the control of my code?
Hi @BDub and thank you for your reply.
I need a way to confirm that the publish was done,
since my device will be used in a place that could suffer internet outrages.
What I’m doing to roughly test the system, is simply turn off the WiFi router while the Photon is sending a series of Particle.publish() instructions. I also added a couple of instructions to turn on the blue LED before the Particle.publish() command and turn it off after. In the moment that I turned off the router the code stopped (wich is great since interrogating the success of Particle.publish() with the router turned off, only resulted in false after 5 more instances of the command, and Particle.connected() never detected the issue), however the blue LED never turned off which indicates that the command never did timeout.
If you are running in default SYSTEM_MODE(AUTOMATIC) without SYSTEM_THREAD(ENABLED) you code will block entirely when the connection is lost.
It’s not only the Particle.publish() that blocks.
I’m running in semi-automatic mode and with system thread enabled. I also did the same test without the flag and the code continued to execute as expected.
Hmm, I just ran a test and it appears with using a iPhone Wi-Fi hotspot, the timeout is 21 seconds, which makes sense because it’s trying to connect to Wi-Fi 3 times at 7 second timeouts for each in the background in WICED.
I wonder what’s different between your router powering off, and my hotspot powering off. When I shut mine down the Photon’s RGB LED is blinking Green. What does yours do? Are you physically turning off the power to the router, or disabling the internet via a control panel on your router?
@gavpret I can confirm there is an unexpected issue here with the WITH_ACK flag. Please watch this issue for the resolution, expected to be fixed in 0.7.0