Problem receiving structure over UDP on Arduino

My setup is I have an Arduino sending a data structure over an Ethernet cable using UDP to another Arduino. The data structure used on both ends is the same. However, weirdly the first 3 values of the data structure are showing as correct at the received end but the others are shown as having a value of 0.00. The transmitted bytes are shown to equal the received bytes at a total of 68 bytes (17 floats).

I know the issue isn't on the transmission end as the data is being received correctly on a Raspberry Pi.

My transmitting code is as follows:

#include "Data.h"
#include <Ethernet2.h>
#include <EthernetUdp2.h>   

byte muMac[] = {0x90, 0xA2, 0xDA, 0x10, 0x5F, 0x92};

IPAddress muIp(192, 168, 0, 30); //Local IP address
IPAddress broadIp(255,255,255,255); //Broadcast address, sends to all nodes (Relay and Station Controller)

unsigned int muPort = 5000; //Local port to listen on
unsigned int broadPort = 8888; //Destination port

EthernetUDP Udp;
Data dataOut;
COMPLEX Impedance;

void Comms_Setup(){
  // start the Ethernet and UDP:
  Ethernet.begin(muMac, muIp);
  Udp.begin(muPort);

  int counter=0;
}

/*Send Following:
 * 1.Peak voltage/current 
 * 2.Phase
 * 3.Frequency
 * Each sample should be timestamped
 */

void send_packet(float idCount)
{
    dataOut.ID = idCount;
    dataOut.CTpvalue=I1.peak;
    dataOut.CTpphase=I1.phase;
    dataOut.CT1value=I2.peak;
    dataOut.CT1phase=I2.phase;
    dataOut.CT2value=I3.peak;
    dataOut.CT2phase=I3.phase;
    dataOut.CT3value=I4.peak;
    dataOut.CT3phase=I4.phase;
    dataOut.CT4value=I5.peak;
    dataOut.CT4phase=I5.phase;
    dataOut.VT1value=V1.peak;
    dataOut.VT1phase=V1.phase;
    dataOut.VT2value=V2.peak;
    dataOut.VT2phase=V2.phase;
    dataOut.VT3value=V3.peak;
    dataOut.VT3phase=V3.phase;
      
    Udp.beginPacket(broadIp, broadPort); //Begin packet to send to a destination IP and Port address

    Udp.write( (byte *)&dataOut,sizeof dataOut); //Write packet which contains data structure 
    Serial.println("Bytes sent");
    Serial.println(sizeof dataOut);
    
    Udp.endPacket(); //Close Packet and send

delay(100);
}

and my Receiving code:

#include <SPI.h>  
#include <Ethernet2.h>
#include <EthernetUdp2.h>   
#include "SampV.h"
#include "Settings.h"

EthernetUDP Udp;
SampV *sampIn; //Instance of sampled value structure
Settings *settingIn; //Instance of settings structure
char DATA_buf[500]; //Temporary buffer to store recieved samples    

byte relayMac[] = {0x90, 0xA2, 0xDA, 0x10, 0x5E, 0xD7};

IPAddress relayIp(169, 254, 255, 155); //IP address of Relay
IPAddress piIp(192, 168, 0, 15); //IP address of Pi

unsigned int relayPort = 8888; //Local port to listen on
unsigned int piPort = 5005; //Destination port


char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //Buffer for settings data

/*Start Ethernet and UDP*/
void Comms_Setup(){
  
    Ethernet.begin(relayMac, relayIp);
    Udp.begin(relayPort);

}

/*Recieve packet from Merging unit*/
void recieve_samples() {

    int packetSize = Udp.parsePacket();
    if(packetSize)
    {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();

    Serial.println("Contents:");

    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i]);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(DATA_buf,UDP_TX_PACKET_MAX_SIZE);

    sampIn = (SampV*)DATA_buf;
    
  Serial.print("ID");
  Serial.println(sampIn->SampID);
  Serial.print("------CTs-------");
  delay(1000);
  Serial.print(sampIn->CTpvalue);
  Serial.print("--");
  delay(100);
  Serial.print(sampIn->CT1value);
  Serial.print("--");
  delay(100);
  Serial.print(sampIn->CT2value);
  Serial.print("--");
  delay(100);
  Serial.print(sampIn->CT3value);
  Serial.print("--");
  delay(100);
  Serial.println(sampIn->CT4value);
  Serial.print("------VTs-------");
  Serial.print(sampIn->VT1value);
  Serial.print("--");
  delay(100);
  Serial.print(sampIn->VT2value);
  Serial.print("--");
  delay(100);
  Serial.println(sampIn->VT3value); 
    }
}

Structure at both ends:

typedef struct {

  float SampID;
  float CTpvalue;
  float CTpphase;
  float CT1value;
  float CT1phase;
  float CT2value;
  float CT2phase;
  float CT3value;
  float CT3phase;
  float CT4value;
  float CT4phase;
  float VT1value;
  float VT1phase;
  float VT2value;
  float VT2phase;
  float VT3value;
  float VT3phase;
}
SampV;

The output at the received end when printing the data is:

Received packet of size 68
From Contents:
192.168.0.30, port 5000
ID37.00
------CTs-------1.87--3.47--2.24--0.00--0.00
------VTs-------0.00---0.00--0.00

Any help is greatly appreciated.

24 bytes.

In EthernetUdp.h, the UDP_TX_PACKET_MAX_SIZE is set to 24.
https://github.com/arduino/Arduino/blob/master/libraries/Ethernet/src/EthernetUdp.h

I guess that the hardware chip can receive the full message, and the software detects the size, but the software layer limits the buffer to 24 bytes.

Koepel:
24 bytes.

In EthernetUdp.h, the UDP_TX_PACKET_MAX_SIZE is set to 24.
https://github.com/arduino/Arduino/blob/master/libraries/Ethernet/src/EthernetUdp.h

I guess that the hardware chip can receive the full message, and the software detects the size, but the software layer limits the buffer to 24 bytes.

Ah, okay. It seems from looking at this post here: Possible to send a UDP packet larger than 24 bytes? - Networking, Protocols, and Devices - Arduino Forum, that it is possible to increase max packet size to send/receive, so I should just change the second parameter in the udp.read() function to something higher than the defined 'UDP_TX....SIZE'

You alread use your buffer of 500 bytes : char DATA_buf [ 500 ] ;
I think you can use sizeof there : Udp.read ( DATA_buf , sizeof ( DATA_buf ) ) ;
Perhaps it is nicer to only read the data packet with sizeof, that would match your Udp.write.

    sampIn = (SampV*)DATA_buf;
    Udp.read( (char *) sampIn, sizeof( SampV));      // read the data packet

I think you don't use the default packetBuffer : char packetBuffer [ UDP_TX_PACKET_MAX_SIZE ] ;
Then you can remove this line.

It is a confusing. The "UDP_TX_PACKET_MAX_SIZE" is not the maximum allowed on the network, but it is used as default for a small buffer with the Ethernet library. It's strange, why is it even defined at all ?

It is strange..

Thanks, that does seem a better way of doing it. The other buffer I was going to use for reading in packet data coming from a different device (RPi).