WiFiClient unable to send more then 92 bytes with println() function

Hello

I recently purchased a Arduino WiFi shield. I connetced the shield to Arduio Mega 2560. I wrote a small TCP/IP client sketch to connect to a PC server. Everything works fine as long as I send less than 92 bytes with each println() or print() or write() function call.

The following code
count = client.println ("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012");
Serial.print("Wrote bytes = ");
Serial.println(count);

The Serial.println() indicates only 2 bytes were written. I confirmed that Server only received 2 bytes by checking with wireshark.

  1. Is there a MAXIMUM Buffer size for TCP DATA?

  2. What else could be causing this behaviour?

Thanks
Shankar

Here is my code

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "MYssid"; //  your network SSID (name) 
char pass[] = "MYPASSWORD";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

IPAddress server(192,168,1,100);  

WiFiClient client;

boolean connecToWiFi()
{
 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) 
  {
     status = WiFi.status();
    // check for the presence of the shield:
    if ( status == WL_NO_SHIELD) 
    {
      Serial.println("WiFi shield not present"); 
      continue;
    }
    
    // Connect to WPA/WPA2 network.
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
  
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
  
  return true;
}

boolean connectToServer()
{
  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  
  client.stop();
  while(client.connect(server, 32155) == false) 
  {
    Serial.println("Can not connect to server");
  }
  
  Serial.println("connection to server successful");
  
  return true;
}

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
  connecToWiFi();
  
  connectToServer();
}

void loop() 
{
  int count;
  // check if the wifi is still connected
  status = WiFi.status();
  if( status != WL_CONNECTED) 
  { 
    connecToWiFi();
  } 

  if (client.connected() == false) 
  {
    connectToServer();
  }

  // send data to server
    
    count = client.write("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012");

    
    Serial.print("Wrote bytes = ");
    Serial.println(count);
  delay(3000);

}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

No limit that I know of.

Wrap your client print in a condition. It might be printing before the server can receive the data.

Thank you for the reply.

If I create a String object and use the string object as the input parameter to println(), then I can send more then 92 byes. But if I define a char dataStr[] and fill it up with data that is more then 92 bytes, it does not work.

For example
const char dataStr[] = "41 00 BE 1F A8 13 >41 0C 0D 12 >41 0D 00 >41 11 2A >41 04 4F >41 05 6A >41 0F 4B >41 46 3A >41 10 01 49 >41 43 00 29 >NO DATA >NO DATA >41 33 64 >41 0E 93 >NO DATA >41 1F 00 27 >41 31 10 BB >\0";

client.println(dataStr); // this only sends 2 bytes "\r\n"

If I declare
String dataStr = "41 00 BE 1F A8 13 >41 0C 0D 12 >41 0D 00 >41 11 2A >41 04 4F >41 05 6A >41 0F 4B >41 46 3A >41 10 01 49 >41 43 00 29 >NO DATA >NO DATA >41 33 64 >41 0E 93 >NO DATA >41 1F 00 27 >41 31 10 BB >\0";

client.println(dataStr);

Then it sends the entire String object contenet. However the Server receives it in 3 Ethernet frames instead of one frame.

What is the difference in using String object and char [] for sending with WiFiClient println() function?

Thanks

Shankar

I did a little googling; there looks like a 62 character limit to char.

Hello mistergreen

Will you please share the reference for the 62 character limit.

Thanks
Shankar