HttpClient library: where does the timeout come from?

Hi guys,

I am playing with the HttpClient library.
My current goal is to POST some data on a server within my local network. I started a conversation here, where we can see the debug log:

HttpClient>  Connecting to IP:
HttpClient>     Start of HTTP Request.
POST /wifispark HTTP/1.0
Connection: close
Content-Length: 19
Content-Type: application/json
Accept: */*
Connection: Close
{"humidity":"43.5"}    //  <-----this is the body of the POST request
HttpClient>     End of HTTP Request.

HttpClient>     Receiving TCP transaction of 85 bytes.
HTTP/1.1 200 OK
Date: Sat, 09 Apr 2016 10:54:46 GMT
Connection: close

Thank you!      //  <-----this is the answer from the server 
HttpClient>     End of TCP transaction.
HttpClient>     Error: Timeout while reading response.

HttpClient>     End of HTTP Response (5700ms).
HttpClient>     Status Code: 200

We can see that a timeout occurs after receiving the response from the server. It seems that the client is still waiting for something in order to close the TCP connection. I made a log of the server-side TCP/IP packets (wireshark format) that you can get here. Among others, we can clearly see that the client is not closing the TCP connection, and sends a [PSH,ACK] instead of sending a [FIN,ACK] (frame number 54 at time 00:52:59.568634000).

Here is the client-side code:

// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"

TCPClient client;
HttpClient http;
IPAddress ServerIP(192, 168, 1, 2); //the IP address of my local server

unsigned int nextHTTPRequest = 0; // Next time to contact the server


http_header_t headers[] = {
    { "Content-Type", "application/json" },
    { "Accept" , "*/*"},
    { "Connection","Close"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL

http_request_t request;
http_response_t response;

void setup() {
    request.port = 80;
    request.path ="/wifispark";

void loop() {
    if( nextHTTPRequest<millis()  )
        request.body = "{\"humidity\":\"43.5\"}";, response, headers);

Any help would be really appreciated.

1 Like

@jipe_rey did you ever figure this out? I’m experimenting with the same thing and haven’t gotten any timeouts yet, but it does seem to block in general while either making the POST request or waiting for the response.

Sorry @policenauts , I did not play with that for years. Actually I am not using Particle products anymore. However, I think Particle or the community came up with new libraries or improvements that could easily replace the HttpClient library from nmattisson (that didn’t get any update since 2017).
I hope you will find another solution for your project.


The request struct has a timeout field in milliseconds that you can use in request.timeout.