fs007
January 7, 2023, 9:40pm
1
Here's a sample piece of code :
EthernetClient client;
client.println(F("HTTP/1.0 404 Not Found"));
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<h2>Error 404</h2>"));
client.println(F("<s2>The file does not exist.<s2>"));
This code works, but it produces TCP packets with a length of 1 byte (!), so one packet for each character to be transmitted, which multiplies traffic by more than 10 !
One should expect that at least one line goes into one packet.
Is there any solution or workaround for this issue ?
J-M-L
January 7, 2023, 9:47pm
2
what proof did you bring? (it's not the case to my knowledge with the current Ethernet library and common Ethernet chips. the writes are buffered)
fs007
January 7, 2023, 9:57pm
3
i can see that in Wireshark
"println( " does produce one line per packet, but "println(F(" makes one character per paket. Try it yourself, if you don't believe me !
Please post your entire sketch. I suspect you have some delays that are forcing it to do that.
Could be caused by print reading from program memory one character at a time
size_t Print::print(const __FlashStringHelper *ifsh)
{
PGM_P p = reinterpret_cast<PGM_P>(ifsh);
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
if (c == 0) break;
if (write(c)) n++;
else break;
}
return n;
}
Printing a null-terminated char array calls write() with the array instead of individual characters
size_t Print::print(const char str[])
{
return write(str);
}
You might need to copy the text from progmem to a buffer to get it sent as a single packet.
1 Like
J-M-L
January 7, 2023, 11:03pm
8
It does call write() which indeed adds one byte to the underlying driver but my understanding was that the layer below was doing the buffering and sending
What chip do you have?
Juraj
January 8, 2023, 7:01am
9
TL;DR use my StreamLib for buffering
Hi,
I have a "smart home" (I hate that term) project which needs internet connectivity.
It uses a common W5500 Ethernet controller and it works just fine.
Every 5 seconds it send ~500 characters long text string message to remote server through HTTP POST.
This is roughly 250MB of useful data per month.
Surprise Motherf*cker! It eats through 2GB data plan in a week. It needs roughly 10GB per month!
How is this possible? Where is the 9,75GB per month coming from? Is the HTTP POST really that…
yes - don't use the F-Makro with the ethernet client.
Use a buffer or the StreamLib library
On this page I cover that topic:
1 Like
fs007
January 8, 2023, 9:58am
11
Thanks to all of you.
The issue is quite clear now and the best solution is probably the StreamLib library.
I'll give it a try.
system
Closed
July 7, 2023, 9:58am
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.