Dropping Connection

I have been working with the Photon 2 where it stays on for several hours at a time without contacting the network. I'm using it as an emergency texting system where you hit a button, and it sends out a pre-written text with Twillio. It is still powered up with a blue slow flashing light on the Photon 2, just not active on the console (no blue light next to the device).

How can I keep the connection alive?

If a Wi-Fi device is breathing cyan but the cloud thinks the device is not connected, it's usually a situation related to the router/firewall on the LAN that the Photon 2/Argon/M-SoM (on Wi-Fi) is connected to, but your situation is a little unusual and it could be something else.

Particle devices send an outbound UDP packet to the Particle cloud. For most networks with NAT, this causes the router to temporarily create a UDP packet receiver on the WAN side and forward it to the Particle device. Since this uses finite resources on the WAN, these are cleaned up after a period of inactivity.

Particle Wi-Fi devices send a packet and get a response every 25 seconds, which is usually sufficient to keep the connection alive. This is a parameter you can change, using Particle.keepAlive().

If the device can't be sent to from the cloud relatively quickly, the network could have an even shorter keep alive than 25 seconds.

Another possibility is that the router removes the return packet routes even if it's actively being used. This is rare but possible, but makes it very difficult to use Particle devices.

The most likely scenario in your case is that the router removes return packet routes after a fixed period of time that's relatively long, but does not depend on activity. This can be worked around by periodically disconnecting from the Particle clound and reconnecting from the device side, which results in using a differnet return port, starting the timer over again.

Thank you for being so quick at responding. I greatly appreciate your help. I've been working with Arduino for years, but I have much less experience with the intricacies of Particle and IoT.

For example, if every couple of hours I use something like:
Particle.disconnect();
delay(2000);
Particle.connect();

or could I do something as simple as request a time synchronization to keep the connection alive?
Particle.syncTime();

Less downtime with time sync.

As I mentioned, your situation is unusual. Usually the next keep-alive will restore the connection. That does not appear to be happening in your case.

The disconnect reconnect is probably the best thing to at least try. However instead of the fixed delay, so:

Particle.disconnect();
waitFor(Particle.disconnected, 10000);
Particle.connect();

Which will wait until disconnected, or 10 seconds. I wouldn't do it too often, but every hour or 90 minutes should be fine and it should only take a second or two.

Thank you, that worked. The downtime during disconnect/reconnect is very tiny, usually less than a second. It's been running for days with a disconnect/reconnect approximately every 2 1/2 hours.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.