-->
Page 1 of 2

HTTP Post request fails after sometime with error -1

PostPosted: Tue Jul 07, 2020 2:06 pm
by m.maazi
Hi! I have an esp-12 module that connects to a server every 3 seconds and runs a php script, then reads the response.
I checked everything to make it work but every time it does it's job 3 to 5 times then reports error -1.
Here is my code for sending POST:

Code: Select allHTTP.begin(ESP_HTTP_ADDRESS);
HTTP.setTimeout(300);
HTTP.addHeader("Content-Type", "application/json");
HTTP.addHeader("Content-Length", String(JSON.length()));

int RESPONSE = HTTP.POST(JSON);
if (RESPONSE != HTTP_CODE_OK) {
  Serial.print(F("Query submit failed: "));
  Serial.println(RESPONSE);
} else {
  Serial.println(F("Query submit successful."));
  Serial.println(F("Reading HTTP response:"));
  String RESULT = HTTP.getString();
  Serial.println(RESULT);
}
HTTP.end();


Could you please guide me to resolve this problem? Thanks.

Re: HTTP Post request fails after sometime with error -1

PostPosted: Wed Jul 08, 2020 12:40 am
by pangolin
We need to see all of the code to be able to answer this - also a Wirehsark trace would be very helpful.

Re: HTTP Post request fails after sometime with error -1

PostPosted: Wed Jul 08, 2020 5:11 am
by m.maazi
Hi. Thanks for helping me.
Posting all my code might be a problem! It's about 10000 lines of code in 40 pages. I stripped my post request code to it's essential commands. My post request is about 300 lines of building a long JSON body for post and decoding an even longer JSON response. I can upload my code.
And about Wireshark. I don't really know how to do it.
Sorry for my poor English.

Re: HTTP Post request fails after sometime with error -1

PostPosted: Wed Jul 08, 2020 6:33 am
by Bonzo
Have you tried slowing it down from 3 to say 6 seconds to see what happens?

You may be trying to send data before the buffer or however it works is full.