I am trying to send TCP packets to a remote server, using the Wemos D1 Mini Pro (ESP8266), configured in lwIP v2 high bandwidth mode (TCP_MSS = 1460
, LWIP_ FEATURES = 1
).
I set a maximum buffer size of 1810 bytes :
#define MAX_BUFFER_SIZE 1810
I declare the buffer as a global static variable :
static uint8_t buffer[MAX_BUFFER_SIZE];
and I am continually sending packetSize
(user-definable size) packets using TCP_write :
uint16_t sent = TCP.write((uint8_t*)buffer,packetSize);
most of the times I get sent
equal to packetSize, however, once a while the function returns a smaller value. For instance, if packetSize = 1135, I usually get the first bad value equal to 650 and a few zero values after that. Normal operation restores after a few failed sends.
I am looking for the reasons behind this fragmentation issue.
Thoughts : should I use a buffer size (currently 1860) smaller than TCP_MSS = 1460, no matter if packetSize
is actually smaller than TCP_MSS
? If yes, should I try to declare buffer
as a dynamic array with size equal to packetSize
?