1

I am trying to send data from one arduino to another over ethernet using udp protocol. In arduino writing data over udp is like this

UDP.write(buffer, size);

where buffer is an array to send as a series of bytes and size is the size of the array.

Now, i am reading a sensor value from a0 pin of the arduino it will be stored either in int or float type variable. As mentioned earlier udp only sends byte type array. so all i want to do is convert the value stored in the variable to the byte type array. my variable will be.

pinMode(A0,INPUT);
int data;
byte data_array[Size];

and in loop

data=analogRead(A0);

now i have convert this value in data_array;

Please provide the suggestion with proper explanation. Thank you

1
  • 1
    UDP.write((const byte*) &data, sizeof(data)); Commented Mar 11, 2021 at 6:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.