arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

HTTP Status code is sometimes equal to -11 after successful post request.

Open ms-somanna opened this issue 1 year ago • 2 comments

Board

ESP32 Dev Board

Device Description

Custom Dev Board

Hardware Configuration

The following modules are attached to the board.

  • Rs485 to TTL converter module
  • RTC module
  • LTE module

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 11

Flash frequency

40 Mhz

PSRAM enabled

yes

Upload speed

115200

Description

I'm fetching energy meter data from the RS485 module, converting it to Json objects and sending the Json data as payload in a http post request to Google Sheets. I'm using the HTTP status code returned by HTTP.GET() function to check if the request was successful or not. The problem is sometimes even after successfully adding the json data to google sheets, the http status code returned is -11. This obviously leads to assuming the request failed even though it succeeded.

Sketch

String url = "https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec";
Serial.println(url);
Serial.println("Making a request");
http.begin(url, root_ca);     //Specify the URL and certificate
http.addHeader("Content-Type", "application/json");
httpCode = http.POST("[" + payload + "]"); 
http.end();

Debug Message

No error/debug messages were captured till now. I haven't yet made the code capture the HTTP response string either. Please do let me know if you require it.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.

ms-somanna avatar Feb 02 '24 08:02 ms-somanna

You can use HTTPClient::errorToString() to turn that into a text response. In this case it is a read timeout, most likely when waiting for the server to give you a response. Google can certainly be slow. Use setTimeout to increase the timeout, default is 5000 (ms).

lbernstone avatar Feb 02 '24 09:02 lbernstone

OP gave a thumbs up to this (very good) answer, but didn't close the issue. It doesn't seem like there's any remaining open action here.

Should this perhaps be closed?

robertlipe avatar Apr 24 '24 16:04 robertlipe