Destination IP address for using UDP

Hi,

I have a requirement to send data coming from a couple of sensors to another device over udp,
supposing the receiving device has an IP of 192.168.7.1 , Where do i write the destination IP address in my code?

all i stumbled upon is

#include <SPI.h>        

#include <Ethernet.h>

#include <EthernetUdp.h>



// Enter a MAC address and IP address for your controller below.

// The IP address will be dependent on your local network:

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192, 168, 1, 177);



unsigned int localPort = 8888;      // local port to listen on



// An EthernetUDP instance to let us send and receive packets over UDP

EthernetUDP Udp;



void setup() {

  // start the Ethernet and UDP:

  Ethernet.begin(mac,ip);

  Udp.begin(localPort);

}



void loop() {

  Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

    Udp.write("hello");

    Udp.endPacket();

}

Kindly pass me the link of any example code if you have.

Also do i have to configure arduino as the client or server?

The above code is working for broadcast, how do i make it work for an destined/intended IP.?

Where do i write the destination IP address in my code?

The EthernetUDP::beginPacket() method takes the IP address (or host name) of the device that you want to talk to. It does not have to be Udp.remoteIP(), unless you are replying to the address that sent you a packet.

Ok Thank you,

So the data i write in to will go to my IP i have set and used in UDP::Begin.

Also, supposing i have 2 sensors from which i am reading data into two variables,'X' and 'Y'.

so, to send this over UDP i have to do the below right..?

Udp.write("X");
Udp.write("Y");

Any changes, like float data is sent differently, integer differently likewise..?

I mean how will my receiving system know that 1st 16 bits is float, 2 bits integer...

so, to send this over UDP i have to do the below right..?

If you want to write the letter X and the letter Y, that is the way to do it. If you want to write the VALUE in X or the VALUE in y, that is not the correct way.

I mean how will my receiving system know that 1st 16 bits is float, 2 bits integer...

It won't. YOU need to send the data in a way that the receiver can handle. Text-based is a good way.

PaulS: If you want to write the VALUE in X or the VALUE in y, that is not the correct way. It won't.

Yes, plz tell me how would i send the value in X and Y? this is my requirement..!!!

#include <SPI.h>        

#include <Ethernet.h>

#include <EthernetUdp.h>



// Enter a MAC address and IP address for your controller below.

// The IP address will be dependent on your local network:

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192, 168, 4, 177);

unsigned int localPort = 8888;      // local port to listen on



// An EthernetUDP instance to let us send and receive packets over UDP

EthernetUDP Udp;



void setup() {

  // start the Ethernet and UDP:

  Ethernet.begin(mac,ip);

  Udp.begin(localPort);

}



void loop() {

  Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

    Udp.write("S");

    Udp.endPacket();

}

Will this write value char ‘S’ on my destination IP 192.168.4.176…?

How can i verify?
The processing code says “hypermedia.net.*;” not found…!!

Will this write value char 'S' on my destination IP 192.168.4.176..?

That is a definite maybe. If you access the UDP server from 192.168.4.176, it will. If you access it from 10.10.0.129, no.

How can i verify?

If you have to ask, you don't have a grasp of using UDP.

The processing code says "hypermedia.net.*;" not found..!!

What processing code?