forked from amcewen/HttpClient
-
Notifications
You must be signed in to change notification settings - Fork 170
Closed
Labels
type: imperfectionPerceived defect in any part of projectPerceived defect in any part of project
Description
Hi everyone, I am posting in hopes that someone may have insight into the issue I'm facing. I am attempting to have my Arduino send POST requests to a webserver on the same network, which is then handled by a PHP script. What I have found is that the POST requests are being handled properly, but that my Arduino is sending out roughly 3 post requests when I am only calling the http.post() method once. Below is my code:
// Send POST request containging time and PID to HOST_NAME:HOST_PORT/PATH_NAME
// POST request will be handled by PHP file on serverside
// DEBUG: sendPOSTHTTP() sends too many POST requests (current testing has it sending three requests instead of one)
void sendPOSTHTTP(uint32_t time, float PID)
{
Serial.println("making POST request");
String contentType = "application/x-www-form-urlencoded";
std::string strTime = std::to_string(time);
std::string strPID = std::to_string(PID);
std::string postData = "PID=" + strPID + "&TIME=" + strTime;
http.post(PATH_NAME, contentType, postData.c_str());
// read the status code and body of the response
int statusCode = http.responseStatusCode();
String response = http.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
}The function calls:
void setup()
{
sendPOSTHTTP(232, 1.234);
sendPOSTHTTP(243, 2.435);
sendPOSTHTTP(423, 4.3);
}I have attempted to add delays between the POST requests to some success but find that even with these delays occasionally more than one POST request is sent for every call of sendPOSTHTTP().
Please let me know if you need more information, thank you!
Metadata
Metadata
Assignees
Labels
type: imperfectionPerceived defect in any part of projectPerceived defect in any part of project