connection failed, program keeps looping data never sends

Hello Im Ed, I'm new & I'm a beginner I'm currently watching tutorials on programming I will get better and understand more of these functions, but I need help.

my Weather station runs great uploads data to site, but my internet is spotty and sometimes goes off line, then comes back but the program keeps looping but never sends data ever again even after internet is back up. I figured out with the serial monitor it was connection failed section printing.

I'll be honest I'm not to the point I can understand and program watchdog yet and I don't want stuck in an endless loop.

system works great again if i hit "resetbutton" on the board

SO HOW DO I code a Reset if the system prints Serial.println("connection failed");

I'm hoping I can just add it to the code below? since its the section that has the issue

//upload temperature humidity data to thinkspak.com
void uploadTemperatureHumidity(){
   if(!client.connect(host, httpPort)){
    Serial.println("connection failed");
    return;
  }

I'm trying this?

will this actively reset the internet connection or is it just garbage

//upload temperature humidity data to thinkspak.com
void uploadTemperatureHumidity(){
   if(!client.connect(host, httpPort)){
    Serial.println("connection failed");
    while (!client.connected()) {
  Serial.println("no connection to server");
  client.connect(httpPort, 80);
  delay(1000);
  }
Serial.println("connection to server ok");
    return;
  }

The best solution would be to figure out what the problem is that causes the code to never recover, rather than putting a bandaid on it with this reset workaround. If you want help with that, you'll need to post the full sketch.

As for the question of how to do a reset, this may depend on which Arduino board you are using.

Edwin101:
will this actively reset the internet connection or is it just garbage

If the call to client.connect() you already had was repeatedly failing, likely that added code will just cause the code to get stuck in the while loop forever.

Edwin101:

  client.connect(httpPort, 80);

I recommend you take a close look at that line. I don't think you got the usage of client.connect() right.

yup, the code didn't reset & just looped your correct!

I'm way above my head, I guess I should go back to books I was just hoping for a patch, till I learned more functions

just wanted a simple If (!client.connect) then reboot

but I don't know how to execute that. I'm 5 days of studying code i'm still a preschooler at this.

11:23:52.938 -> light: 183
11:23:52.973 -> Pressure = 96548 Pascal
11:23:59.998 -> temp:21 humi:30
11:24:00.137 -> light: 185
11:24:00.172 -> Pressure = 96544 Pascal
11:24:07.228 -> temp:21 humi:29
11:24:07.333 -> light: 196
11:24:07.366 -> Pressure = 96552 Pascal
11:24:14.411 -> temp:21 humi:29
11:24:14.516 -> light: 194
11:24:14.551 -> Pressure = 96554 Pascal
11:24:22.899 -> connection failed
11:24:22.899 -> no connection to server
11:24:28.911 -> no connection to server
11:24:34.926 -> no connection to server
11:24:40.913 -> no connection to server
11:24:46.936 -> no connection to server
11:24:52.926 -> no connection to server
11:24:58.929 -> no connection to server
11:25:04.928 -> no connection to server
11:25:10.934 -> no connection to server
11:25:16.920 -> no connection to server

We can help you, but only if you provide the necessary information.