TCPClient random disconnect

Hi folks,

Does anybody know how to solve a TCPClient random disconnect?

I'm running a personal weather station and uploading data to Weather Underground (WU) using a Photon 2. The Photon never drops the Wi-Fi connection — I can always see it connected via my phone — but the upload to WU intermittently fails.

At the top of my file, I'm trying to make sure WiFiClient maps to TCPClient, as Arduino code often uses WiFiClient successfully:

// Whenever we write WiFiClient, treat it as TCPClient.
#if defined(PARTICLE) 
using WiFiClient = TCPClient;  
#endif

This doesn't seem to help.

Here's how I start the Weather Underground setup:

char server[]  = "rtupdate.wunderground.com";
char WEBPAGE[] = "GET /weatherstation/updateweatherstation.php?";
char ID[] = "KCAPALMD170";
char Key[] = "XXXXXXXX";

void wxUnderground()
{
    TCPClient client;
    ...
}

To work around the issue, I implemented a watchdog, and that does work — the device resets the WU connection, and recovers when it fails. But ideally, I want to prevent the disconnects in the first place.

Any ideas on why the TCPClient connection is dropping, or tips to make it more stable when uploading to WU?

Have a good one,

Alex

Hi, I’m not sure if a tcp connection that once established never disconnects exists. There are so many things in the middle that it seems very hard to achieve.

If I had this problem I would focus on monitoring the TCP connection and when it drops, simply reconnect. If the upload fails, then retry that as well.

If the reconnection fails, do some retries and then last resource reset the device as you mentioned.

Best of luck!

1 Like

ok

You always need to account for a TCP connection being closed because it can happen at any time, not only with your local Wi-Fi, but also your connection to the Internet, and anywhere on the Internet, if you are accessing a remote server.

You can lose a TCP connection and not lose the cloud connection. Because the cloud uses UDP, you can have an interruption of up to 20 seconds without it affecting the cloud connection if actively exchanging data, or up to a couple minutes if idle. The DTLS protocol used by the cloud connection is designed to be tolerant of losing the connection.

1 Like