0

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 ?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • I am betting that you are calling TCP.write() until the underlying tx buffer is full. This buffer is likely a multiple of TCP_MSS. if the underlying buffer is TCP_MSS * 2 in size, then calling TCP.write(1135) just 3 times will result in only stuffing 650 bytes into the tx buffer. – Stephen Klein Jun 03 '22 at 21:33
  • Yes, this is exactly what it happens. The TCP_SND_BUF is 2 * 1460 = 2920 and it gets stuffed with three 1135 packets, so the last one reads as 650. I couldn't find a way to increase this buffer, even when editing lwipopts.h. My module is Wemos D1 mini pro. – Vassilis Papanikolaou Jun 22 '22 at 11:54

0 Answers0