Hello to all, i would like to ask for some help about UDP and ethernet shield with my Arduino Uno.
I want to read analog values from a sensor on the Arduino side, make some changes etc and send a string via UDP to the pc.
So the questions begin at the example here: Ethernet - Arduino Reference
void loop() {
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("hello");
Udp.endPacket();
}
What i have understood is that remoteIP and remotePort get values when the pc side sends a packet to the Arduino and it replies to this "address" with name and number. That is what i don't want to do, send any data from the pc to the Arduino. So i have commented it out in the example below.
(the example here http://arduino.cc/en/Tutorial/UDPSendReceiveString , sets the same IP and the same port in the processing script as in the arduino script [pc-arduino sides] ).
I have set a static IP on the pc side that i connect the ethernet [serverName] .
Lets see a specific example again , so i would be grateful if we could modify the codes so they fit my needs:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,3,3 };
byte serverName[] = { 192,168,3,2 }; //static IP
unsigned int localPort = 8888;
float valFloat;
EthernetUDP Udp;
void setup()
{
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop()
{
valFloat = ( analogRead(i) * 500.00) / 1024.00;
//Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
String STRING = "blablabla";
Udp.beginPacket(udpIP, udpPort); ////////// WHAT VALUES????????
Udp.write(STRING);
Udp.endPacket();
delay(1000);
}
/*
Processing sketch to run with this example
=====================================================
// Processing UDP example to send and receive string data from Arduino
// press any key to send the "Hello Arduino" message */
import hypermedia.net.*;
UDP udp; // define the UDP object
void setup() {
udp = new UDP( this, 8888); // create a new datagram connection on port 8888 (had 6000)
udp.listen( true ); // and wait for incoming message
}
void draw()
{
}
/* THIS IS WHAT I DONT NEED AT ALL, PC SENDING DATA TO ARDUINO
void keyPressed() {
String ip = "192.168.2.7"; // the remote IP address
int port = 3306; // the destination port
udp.send("Hello World", ip, port ); // the message to send
}*/
void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, String ip, int port ) { // <-- extended handler
for(int i=0; i < data.length; i++)
print(char(data[i]));
println();
}
Thank you all in advance for the time spent and for any thoughts!