Arduino UNO WiFi Rev2 - Post Request take 5 secs to response

Hi guys!

I am using an Arduino UNO WiFi R2 and the library <ArduinoHttpClient.h>. On this one I am making a POST request, which is taking about 5 seconds to respond. Obviously the POST request should take time, however if I send the request from Postman, the response is fast.

Does anyone have any idea how to make the response on the Arduino faster?

void loop() {
 
    sendCardUID();

}

int sendCardUID(){
    
    String path = ENDPOINT_URL_SENDUID;    
    String contentType = CONTENT_TYPE_APPJSON;
    String postData = "data";
        
    Serial.println("Making POST request...");
    
    client.post(path, contentType, postData);
    
    int statusCode = client.responseStatusCode();
    String response = client.responseBody();

    Serial.print("Status code: ");
    Serial.println(statusCode);
    Serial.print("Response: ");
    Serial.println(response);
    
}

If that’s your code, you’re possibly swamping the web server with too many requests.

I'm actually making a single request, the response status code is 200, but that response delays. For now that's all my code is doing.

void loop() {
  if(nRequest == 0){  
    sendCardUID();
    nRequest = 1;
  }
}

int sendCardUID(){
    

  String path = ENDPOINT_URL_SENDUID;    
  String contentType = CONTENT_TYPE_APPJSON;
  String postData = "data";
        
  Serial.println("Making POST request...");
    
  client.post(path, contentType, postData);
    
  int statusCode = client.responseStatusCode();
  String response = client.responseBody();

  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);
  
  return statusCode;
}

Additionally, is it possible that while the POST request is responding, other functions can be executed inside the code? Something asynchronous or using threads?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.