Problem with UDP frames on Arduino Ethernet

Hi everyone :slight_smile:

I want to establish a communication between two Arduino Ethernet boards. The first one stores data into 6 variables (which are int, so weighs 16 bits). I have to send these 6 values to the second board via UDP frames.

Here is a part of my programm about these frames:

Udp.beginPacket( /IP_ADRESS/ , /PORT/ );
Udp.write(a);
Udp.write(b);
Udp.write(c);
Udp.write(d);
Udp.write(e);
Udp.write(f);
Udp.endPacket();

First : admitting that the a variable is set to 0000000000111111. When I write it in the UDP frame with Udp.write(), Will the 10 zeros be conserved (Even if they are useless) or will they just disapear?

Iā€™m also a bit lost concerning the reception of the frame by the second Arduino board. With 6 int variables, the frames reaches 96 bits long (only counting the data).
If I write each variable in the order above, Were will be stored the first one I wrote (a)? In the MSB side of the frame or in the LSB side? :roll_eyes:

Thank you for reading it, enduring my english (Iā€™m french XD)

Paul.

First : admitting that the a variable is set to 0000000000111111. When I write it in the UDP frame with Udp.write(), Will the 10 zeros be conserved (Even if they are useless) or will they just disapear?

The value being written to the frame is 0b111111. The fact that you think of it as having 10 leading zeros is of no significance.

If I write each variable in the order above, Were will be stored the first one I wrote (a)? In the MSB side of the frame or in the LSB side?

You need to investigate what UDP.write() takes as an argument. Does it accept a byte? Or does it accept an int? If it accepts only a byte, what does it do to the value if you supply an int? Is the high order byte discarded?

The order of data in the frame is the order that you wrote it. The question is how big the things are that can be written to the frame. Don't shoot yourself in the foot by making (stupid) assumptions.

Don't shoot yourself in the foot by making (stupid) assumptions.

There are no assumptions for my part, only stupid questions. ;)

Thanks for your help PaulS

There are no assumptions for my part

Yes, there are. You are assuming that Udp.write() accepts an int. Typically, write() methods do not. You need to verify that Udp.write() is defined to take an int.

Look at the ethernet UdpNtpClient example for a good way to send raw data.