Size limit on UDP packets? I can't exceed 90 characters

Hey,

I’ve got a program where I want to send a string of analog pin readings to a computer in a UDP packet using a WiFi shield. I wanted to sample the analog pin every 10 milliseconds, and send a packet every 50 samples. This would equate to 2 packets per second.

I’m using the String class to create a string of comma separated values, each value is my analog pin reading. However, not all of the data gets through. I looked at the packets being sent using Wireshark, and sure enough, only the first 10 measurements or so got through. The data was always truncated after 29 bytes.

My code for this is below:

void loop()
{ 
  Udp.beginPacket(broadcastIP, 8888);   
  dataString = "";
  for(count1 = 0; count1 < 50; count1++)
  {
    dataString += analogRead(A0);
    dataString += ",";
    
    delay(10);
  }

  Udp.print(dataString);
  Udp.endPacket();
}

After finding that not all the data was being sent/received, I thought maybe the String class was messing with things, so I modified the UdpNtp example to send a large packet to the broadcast address (255.255.255.255) to see if I could get it in wireshark. The entire modified program is below:

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

int status = WL_IDLE_STATUS;
char ssid[] = "OPL_EKG";  //  your network SSID (name)
unsigned int localPort = 2390;      // local port to listen for UDP packets
IPAddress broadcastIP(255, 255, 255, 255); // time.nist.gov NTP server
const int NTP_PACKET_SIZE = 90; // size limit seems to be 90
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 

// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid);
    delay(5000);
  }

  Serial.println("Connected to wifi");
  printWifiStatus();
  Serial.println("\nStarting connection to server...");
  Udp.begin(localPort);
}

void loop()
{
  sendNTPpacket(broadcastIP); // send an NTP packet to a time server
  delay(1000); 
}

// send an NTP request to the time server at the given address 
unsigned long sendNTPpacket(IPAddress& address)
{
  //Serial.println("1");
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE); 
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  //Serial.println("2");
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49; 
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  packetBuffer[67] = 'A';//double quotes give a conversion error
  
  //Serial.println("3");

  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp: 		   
  Udp.beginPacket(address, 3000); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket(); 

}
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");
}

you’ll notice I have NTP_PACKET_SIZE set to 90. I found that if I go any higher than 90, no data is received in Wireshark at all, despite still being able to connect to the wifi network

Any clue why this might be? Is it possible that I’ve run out of SRAM?
Thanks a lot

I’m using the String class

Stop right there. Learn to do it right, using C style strings. Quit pissing memory away.

Is it possible that I’ve run out of SRAM?

Have you checked?
http://playground.arduino.cc/Code/AvailableMemory

It seems to be a problem with the wifi shield. http://forum.arduino.cc/index.php?topic=208913.0

I use 48 to 64 byte packets, so I don't see the problem.