espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.03k stars 7.3k forks source link

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

Open ms-somanna opened 5 months ago

ms-somanna commented 5 months ago

Board

ESP32 Dev Board

Device Description

Custom Dev Board

Hardware Configuration

The following modules are attached to the board.

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

lbernstone commented 5 months ago

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).

robertlipe commented 2 months ago

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?