Code:
void loop() {
/********************************************************
Tablette -> Arduno Mega
********************************************************/
int packetSize = Udp.parsePacket();
if (packetSize)
{
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
//1 : on transmet la requete a l'arduino mega
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
}
Serial.printf("%s\n", incomingPacket);
/********************************************************
Arduno Mega -> Tablette
********************************************************/
String data;
char a=-1;
unsigned long start = millis();
while ((millis() - start < 1000) ) {
while(Serial.available() > 0) { //tant qu'on recoit des donne on rempli data
a = Serial.read();
data += a;
//Serial.print(data);
if(a == '\r') {
//Serial.printf("CR recu\r\n");
break; //si eof, send data to Tablette
}
}
if(a == '\r'){ //si l'octet recu est zero, on arrette et on transmet a la tablette
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); // send back a reply, to the IP address and port we got the packet from
Udp.write(data.c_str());
Udp.endPacket();
break;
}
}//end timeout
if(a != '\r'){
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); // send back a reply, to the IP address and port we got the packet from
Udp.write("Arduino Timeout...\r");
Udp.endPacket();
}
}//end if requete udp recu
}//end loop
Statistics: Posted by Olfox — Thu Apr 20, 2017 9:03 pm