Connecting to googlesheets

Hi guys,

I have a problem connecting to google sheets. What happens is the ESP connects and sends two readings to the sheet. It does this a few times and then suddenly says "connection failed" and then stops. After this the only way to restore the connection is to reset the ESP manually. Do you guys have any idea what might cause this?

I've thought that it might be that the ESP is sending data faster than googlesheets can handle the data and then it loses connection, so I've implemented delays etc. but this still doesn't work.

I'll post the method below that I use to send the data, thank you.

void sendData(int tem, int hum)
{
  Serial.print("connecting to ");
  Serial.println(host);
  delay(1500);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
  }

  if (client.verify(fingerprint, host)) {
  Serial.println("certificate matches");
  } else {
  Serial.println("certificate doesn't match");
  }
  String string_temperature =  String(tem, DEC); 
  String string_humidity =  String(hum, DEC); 
  String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_temperature + "&humidity=" + string_humidity;
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
         "Host: " + host + "\r\n" +
         "User-Agent: BuildFailureDetectorESP32\r\n" +
         "Connection: close\r\n\r\n");


 delay(2000);
  
}

This is not your complete code, while the code you presented looks fine, you could have issues else where. You should consider posting all your code.

The only other comment I have for you.

You should avoid String as it leads to memory fragmentation and bad things can happen in the code. You should use c style strings.
https://www.learncpp.com/cpp-tutorial/66-c-style-strings/

  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
  }

  if (client.verify(fingerprint, host)) {

If you connected, verify the fingerprint.

If you failed to connect, verify the fingerprint.

If you don't give a sh*t whether you connected, or not, why do you bother printing a message if you don't connect?