Hi,
1.
You must add buffering
2.
RS232 is character based but TCP is packet based.
As a result of the different data handling if you do not buffer data it means that for every byte you send from
RS232 you send a TCP packet that has one data byte. That means you have a huge overhead on every byte.
This is very un-efficient and causes the system to get very slow.
I have implemented a Bridge, used a 255 byte buffer and set two parameters: size and time.
Size: If you reach a predefined number of bytes you send them in one TCP packet.
Time: If you do not get any new data into the TCP buffer after a predefined time you send what you have.
This way you collect data from UART and send it in chunks/packets.
For example you define 100 bytes as threshold or 30ms as time threshold. Every byte added from UART
To the send buffer is counted. Once the counter reaches 100 or if no new byte is added after 30ms the
TCP buffer is sent and parameters are cleared.
I also suggest using a small MSS size (I use 536 bytes).
BR,
Noam.
From: lwip-users [mailto:address@hidden
On Behalf Of Erkan Ersoy
Sent: Saturday, September 17, 2016 1:42 PM
To: Mailing List for LwIP Users
Subject: [lwip-users] long time tcp receive lwip packets lost
I am making a serial tcp bridge device. it works in server mode I have freeRTOS 9, lwip 1.4.1 and STM32F107 device
I wrote the bridging part and for testing purposes I didn't implement buffer to TCP to serial. So Some while receiving data some data piles up in somewhere
in tcp thread (I think).
I wrote a python script that sends 2096 characters every second (some lorem ipsum text). serial speed is 115200. So there is enough time to send data
and free memory.
But after couple of hours (it is random. sometimes 2 hours sometimes 4 and yesterday it was 12 hours) device cant receive whole data somewhat it is
80 byte parts.and it piles up in tcp part. And after I stop my script I continue to get data from my serial window a few seconds. After memory is empty if I start my script again still same problem.
I enabled stats to see if I am getting out of memory but it looks fine. I couldn't find where my problem is.
There is a web server and an udp server running in device (I didnt send request both server while testing)
my stats before running test (it sends stat to seperate uart every 10 seconds)
accept_function: newpcb->state: ESTABLISHED
And after the problem (Nothing seems suspicious except cachehit I could't figure out what it is)