ESP8266HTTPClient issue in library · Issue #7049 · esp8266/Arduino (original) (raw)
Message bigger than 1460 bytes can't be send.
ESP8266HTTPClient.CPP
Problem is in:
Function: int HTTPClient::sendRequest(const char * type, const uint8_t * payload, size_t size)
// send Payload if needed if (payload && size > 0) { size_t bytesWritten = 0; const uint8_t *p = payload; while (bytesWritten < size) { int written; int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE); written = _client->write(p + bytesWritten, towrite); if (written < 0) { return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } else if (written == 0) { return returnError(HTTPC_ERROR_CONNECTION_LOST); } bytesWritten += written; size -= written; } }
Problematic is:size -= written;
- because SIZE is subtracting every loop and then in WHILE is compared to overal bytes sent. Only first chunk 1460 bytes can be send.
Solution:size -= written;
- this should be erased.bytesWritten += written;
- this is enough for this function.
Proper code is:
// send Payload if needed if (payload && size > 0) { size_t bytesWritten = 0; const uint8_t *p = payload; while (bytesWritten < size) { int written; int towrite = std::min((int)size, (int)HTTP_TCP_BUFFER_SIZE); written = _client->write(p + bytesWritten, towrite); if (written < 0) { return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED); } else if (written == 0) { return returnError(HTTPC_ERROR_CONNECTION_LOST); } bytesWritten += written; //size -= written; } }