How to correctly use TCPSocket

Hi Jan,

Have a look here, I had the same issue and this sorted the problem out for me.
I use Studio off-line and working with the latest OS5 and OS6.

Ping function to help overcome long connect timeout

I use this snip to collect data from various devices on my local network (Ethernet of ESP8266 WIFI), then POST data to and from Firebase periodically.
200ms timeout works for me (I have tested it working at 10ms ) in case the IP drops or there’s an unsuccessful connect attempt for any reason.
I find it takes around 3ms to connect and send/receive 64 bytes of data.
It has been running solid for two weeks (24/7)so far.

void get_remote_device(int device) {
  TCPSocket remote_device;
  SocketAddress remote_addr(clientaddress, 80);
  remote_device.set_timeout(200);
  remote_device.open(net);
  if (remote_device.connect(remote_addr) == 0) {
    char sendbuffer[] = "GET /data\r";
    int buffer_size = strlen(sendbuffer);
    remote_device.send(sendbuffer, strlen(sendbuffer));
    int rec_count = 0;
    char recbuffer[128];
    rec_count = remote_device.recv(recbuffer, sizeof(recbuffer));
    recbuffer[rec_count] = '\0';
    // printf("receive buffer: %s count: %d\n", recbuffer,strlen(recbuffer));
    if (device == 0) {
      sscanf(recbuffer, "%f %f %f %f %f %d %s %d", &data[0], &data[1], &data[2],
             &data[3], &data[4], &Buffer_RSSI, Buffer_SSID, &Buffer_rtc);
    }
    if (device == 1) {
      sscanf(recbuffer, "%f %f %d %d %d %d %d %d %d %s %d", &waterlevel,
             &tanktemp, &gardenpump, &valve[0], &valve[1], &valve[2], &valve[3],
             &valve[4], &Tank_RSSI, Tank_SSID, &Tank_rtc);
    }
  }
  remote_device.close();
}