diff --git a/src/app/HttpClient.cpp b/src/app/HttpClient.cpp index 5fc1e3d..095291a 100644 --- a/src/app/HttpClient.cpp +++ b/src/app/HttpClient.cpp @@ -7,7 +7,7 @@ * End of HttpClientHelper */ -HttpClient::HttpClient() : WiFiClient(), _connectionStatus(NO_ATTEMPT), _resource(NULL), _address(NULL), _port(0), _keepAlive(false), _maxRetries(5), _retries(0), _httpCode(HTTP_CODE::UNDEFINED_CODE), _bodyReadyToRead(false) +HttpClient::HttpClient() : WiFiClient(), _connectionStatus(NO_ATTEMPT), _resource(NULL), _address(NULL), _port(0), _keepAlive(false), _maxRetries(-1), _retries(0), _httpCode(HTTP_CODE::UNDEFINED_CODE), _bodyReadyToRead(false) { } @@ -106,22 +106,30 @@ boolean HttpClient::sendHttpQuery(const char *resource, HttpRequestMethod method boolean HttpClient::sendHttpQuery(HttpRequestMethod method, Dictionary *getData, Dictionary *postData) { + //We reset this two flags _httpCode = HTTP_CODE::UNDEFINED_CODE; _bodyReadyToRead = false; + #ifdef DEBUG_HTTP_CLIENT - Serial.printf("Link status : %d\n", status()); + if(_keepAlive) + Serial.printf("Link status : %d\n", status()); #endif if(!connected() || _connectionStatus == FAILED) { if(_retries == _maxRetries) return false; + if(_connectionStatus == FAILED) { stop(); - _retries++; + if(_maxRetries != -1)_retries++; } + #ifdef DEBUG_HTTP_CLIENT - Serial.printf("Link broken, we try to reconnect : addr : %s port %u\nretries : %u\n", _address, _port, _retries); + if(_keepAlive) + Serial.printf("Link broken, we try to reconnect : addr : %s port %u\nretries : %u\n", _address, _port, _retries); + else + Serial.printf("We start a new connection : %s port %u\nretries : %u\n", _address, _port, _retries); #endif connectByHostOrIp(); @@ -333,3 +341,8 @@ uint64_t HttpClient::computeBodyLength(Dictionary *getData = NULL, Dictionary *postData = NULL); boolean sendHttpQuery(HttpRequestMethod method = HttpRequestMethod::GET, Dictionary *getData = NULL, Dictionary *postData = NULL); void keepAlive(boolean enabled); + void setMaxRetries(int16_t retries); HTTP_CODE isReplyAvailable(); @@ -42,8 +43,8 @@ class HttpClient : public WiFiClient, public HttpConstants char *_address; uint16_t _port; boolean _keepAlive; - uint8_t _maxRetries; - uint8_t _retries; + int16_t _maxRetries; + uint16_t _retries; HTTP_CODE _httpCode; boolean _bodyReadyToRead; };