Something sent a UDP packet. That something made the data available for parsePacket() (stupid name) to copy to a buffer. parsePacket() then tells you how much data is in the buffer, and read() gets the data from the buffer into your array.
Thanks, for this explanation.
The Sketch is now Working as i want
[code]
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet2.h>
#include <EthernetUdp2.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
byte mac[] = {
0x90, 0xA2, 0xDA, 0x10, 0x22, 0xEE
};
//Einstellung MAC adresse //Settings MAC addresse
IPAddress ip(172, 17, 17, 210);
IPAddress gateway(172, 17, 17, 1);
// IP Einsellungen //Ip settings
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //save the data
int Paket; //Variable to save the size of the data
EthernetUDP Udp; //use UDP
int LED = 5; //LED PIN
void setup()
{
SPI.begin(); //Beginne den SPI-Bus
digitalWrite(4,HIGH); //SD-Pin
Ethernet.begin(mac, ip); //Starte dei IP-Einstellungen
Udp.begin(8888); //Öffne den Port
pinMode(LED, OUTPUT); //Pin 5 = OUTPUT
Serial.begin(9600); //Beginne die Serielle Übertragung
//Start the serial Monitor
}
void loop()
{
Paket = Udp.parsePacket(); //Empfange packet //receive the Packet
if(Paket)
{
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); //read the data
String stringOne = String(1); //create String from 1
Serial.println("Contents:");
Serial.println(packetBuffer);
if(stringOne.equals(packetBuffer))
//show if the data from the buffer and stringOne are equal
{
int a = digitalRead(5); //read the Value from Pin 5
if(a==HIGH) {digitalWrite(5, LOW);} //Changethe Value from Pin 5
if(a==LOW) {digitalWrite(5, HIGH);} //Change the Value from Pin 5
}
for(int c=0;c<UDP_TX_PACKET_MAX_SIZE;c++) //erase buffer
{
packetBuffer[c] = 0;
}
}
delay(90);
}
[/code]