Yes, there is an upper limit, but you are not even close. The max you can send at a time is about 1400 characters, but most Arduinos do not have enough SRAM for a buffer that big. If you try that with an Uno, you would run out of SRAM.
edit: This applies to the ethernet shield. I don't know about the Wifi shield. I have sent 500 characters at a time with my Mega/ethernet shield, but the code would not run on an Uno due to SRAM limitations.
Thanks SurferTim. I am using a MEGA so memory should not be the problem. I will also check with the web master for more clues. I suppose the lower layer SPI functions might have limit on max length?! But I client.write somehow fragments the packet as needed?
Thanks for your help. Here is the code that sends the packet to the server:
Original code that stops working (returning 0) when the string becomes too long (100 bytes is too long, 90 is not. I wasn't patient enough to find the exact limit)
int SendPacket(char* buffer)
{
unsigned long connect_time;
if (client.connect(server, 1035))
{
connect_time=millis();
Debug->println("Connected to server");
client.println(buffer);
}
else return 0;
while (!client.available())
{
if (millis()-connect_time>server_response_time)
{
client.stop();
return 0;
}
}
return client.read();
}
Modified code that does multiple client.println(), which works. In this code, the caller needs to intentionally insert separators (I chose '~') within the long string so this function will replace them with '\0' (fragment the long message) and send the long message one fragment at a time.
int SendPacket(char* buffer)
{
int nptr=1,i=0;
int ptrs[10];
ptrs[0]=0;
unsigned long connect_time;
if (client.connect(server, 1035))
{
connect_time=millis();
Debug->println(F("Connected to server"));
while ((buffer[i]!='\0'))
{
if (buffer[i]==string_segment_marker) // found one marker
{
buffer[i]='\0'; // replace with \0
ptrs[nptr]=i+1; // store the pointer to the next string segments
nptr++; // increment the number of pointers or segments
}
i++;
}
for (byte j=0;j<nptr;j++) // print strings segment by segment
{
client.println(buffer+ptrs[j]);
}
}
else return 0;
while (!client.available())
{
if (millis()-connect_time>server_response_time)
{
client.stop();
return 0;
}
}
return client.read();
}
The server was working fine with a cell modem and library but I recently added more digits to each value in the long message and have not tested it since. I could reassemble the other prototype that has cell modem and test the long message via cell modem just to make sure the server is not to be blamed.
Hello, I using ESP8266 there is a lot of memory. I discovereded that the upper limit for client.println() function is 2922bytes. Is it possible to pull up this limit? I using ESP8266 for webserver and html(where I have lot of code, javascripth graphs, etc..) page going through this function. Thank You.
woodwax:
Hello, I using ESP8266 there is a lot of memory. I discovereded that the upper limit for client.println() function is 2922bytes. Is it possible to pull up this limit? I using ESP8266 for webserver and html(where I have lot of code, javascripth graphs, etc..) page going through this function. Thank You.
How did you determine the ESP8266 can send a packet larger than 1492 bytes? What code did you use to send the 2922 bytes?
String s = "var temperature=[";
for (i=0; i < temperature.count; i++)
{
s += temperature.saved[i];
s += ",";
}
s += "];\n var epoch=[";
for (i=0; i < temperature.count; i++)
{
s += temperature.epoch_saved[i]-7200;
s += ",";
}
s += "];\n";
Serial.print("Bytes sent:");
Serial.println(client->println(s));
The String s is enough large. The data sent by client->println(s) function is in file sent_data.txt. You can clearly see the epoch array is not comleted (lack of some characters and ]; ) and it contains 2921 characters + maybe terminating.
On picture bytes_sent.png is the serial output an there is the 2922 bytes sent.
I have just been writing a program using ESP8266 WifiClient client.print. And I can verify that the maximum is just under 3000 bytes. I believe the size stated above (2922) is probably correct. I wish it was larger and don't yet know why but will investigate. It does not cause an error to try to print a longer string but it does truncate it so there must be a buffer somewhere that is limiting the size.
It has been found by several people that multiple client.print statements are slow so I build up the string as long as I can before doing the client.print. Doing that, it is reasonably fast. Also, using WiFiClient allows me to leave the connection open for more speed.
Previously, I was using ESP8266WebServer and there is a limit there, too. It is larger. Something around 8KB and it won't go above that. I was not able to find how to do multiple httpServer.send(200, "text/html" style commands so I converted to the lower level WifiClient library code. This gives me access to all of the input lines from the browser and I can track browser type, environment and IP address:port.
There is a hierachy here:
ESP8266HTTPUpdateServer (OTA server) is on top of ESP8266WebServer which is on top of WiFiServer.
The program is currently 1600 lines. If someone wants it, I can send it or put it on my web server and post a link. It reads 3 types of temp sensors, also reads Barometric Pressure and Humidity, writes to OLED and SD (history files) and sends out a web page with lots of information including an .svg graphic with 3 symbols and two text lines. If the sensors are missing, it goes on with what it has. I tried to make it not break so easily as some programs.