wifi udp write is truncating packets to 29 bytes

I have an odd issue. I’ve got a arduino wifi shield attached to an arduino uno (I’ve also tried with a mega 2560), and I am attempting to send a udp packet to a host computer using the wifi library. I’m running arduino 1.5.6-r2 if that matters. The wifi gets connected, and I’m able to transmit packets up to 29 bytes, after that, the packet just gets cut off.

I’m using wireshark to determine the actual bytes sent, so that I can eliminate any issues with the receiving computer. In wireshark, it shows the first packet with a data length of 27 bytes, and the second packet with a data length of 29 bytes. I expect to see 31 bytes in the second transmission. The actual data transmitted is correct, its just truncated to 29 bytes.

I’ve also tried to change it to use the udp write(char *, len), function, but that has similar results.

I cannot get more than 29 bytes to transmit. Does anyone have any ideas why this might be the case?

Below is the entire code

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

char ssid[] = "BlueCedar";          //  your network SSID (name) 
char pass[] = "XXXXXXXXX";   // your network password

int status = WL_IDLE_STATUS;
//IPAddress server(192,168,0,13);  

// Initialize the client library
WiFiUDP udp;

bool WifiEnable()
{
	digitalWrite(4, HIGH); // SD Card not active
	digitalWrite(10, LOW);  // Ethernet ACTIVE
}

void setup() 
{
	Serial.begin(115200);
	pinMode(4, OUTPUT);
	pinMode(10, OUTPUT);
	WifiEnable();
	Serial.println("Attempting to connect to WPA network...");
	Serial.print("SSID: ");
	Serial.println(ssid);

	status = WiFi.begin(ssid, pass);
	   // delay(10000);
	if ( status != WL_CONNECTED) 
	{ 
		Serial.println("Couldn't get a wifi connection");
		while(true);
	} 

	Serial.println("Connected to wifi");
	Serial.println("\nStarting connection...");
	char buffer[256];
		
	strcpy(buffer, "12345678901234567890123456789012345678901234567890123456789012345678901234567890");

	Serial.println("Sending Packet");
	udp.begin(11000);

	int j;


	udp.beginPacket("192.168.0.13", 30040);
	for (j=0;j<27;j++)
	{
		if (1 != udp.write(buffer[j]))
		{
			Serial.println("Could not write byte");
			while(1) {}
		}
	}
	if (1 != udp.endPacket())
	{
			Serial.println("End Packet Failure");
			while(1) {}
	}

	udp.beginPacket("192.168.0.13", 30040);

	for (j=0;j<31;j++)
	{
		if (1 != udp.write(buffer[j]))
		{
			Serial.println("Could not write byte");
			while(1) {}
		}
	}
	if (1 != udp.endPacket())
	{
			Serial.println("End Packet Failure");
			while(1) {}
	}

	Serial.println("Finished Sending Packet");
}


void loop() {

}

Maybe you have to change this line in WiFiUDP.h:

#define UDP_TX_PACKET_MAX_SIZE 24

John, I appreciate the suggestion. I changed it to 150, but unfortunately it still only sent the 29 bytes. I was very hopeful as the limit did sound promising. I’m open to any other suggestions you or others may have. Thanks.

The limit is around 90 bytes if you have upgraded the firmware.

Have you upgraded the wifi shield firmware?

Surfer -- I am pretty sure I did upgrade the firmware per the arduino wifi shield websites specs ... I did that about 2 months ago or so. I also did see the post you referred to, but those guys are getting 90 bytes out ... I'll go and try to update the firmware again, as my memory has failed me on more than one occasion. I can probably live with 90 bytes of data. Thanks for your suggestion, and I'll post back as to whether it worked.

Firmware has been upgraded. 29 bytes still seems to be the maximum number of chars I can send via UDP.

I send 48 bytes all the time. 64 bytes works good for me. I use the WiFiUdpNtpClient sketch in the WiFi examples as a test. It sends and receives 48 byte packets, at least the last time I checked.

How are you determining it is sending only 29 bytes?

edit: Are you still using wireshark to determine that?

Yes wireshark -- I was originally using a udp server on my PC, and could not understand why it was not working, as that showed the same thing. So I then decided to take out the receiverr and use wireshark to see if the packet was there. Wireshark shows 27 and 29 bytes sent, and the actual packet itself in wireshark is only 27 and 29 bytes of data. I'll take your advice and just try that and see if its something in my program, but as you see the program basically just opens the connection and sends the data, nothing else.