Arduino Forum

Development => Other Software Development => Topic started by: dizzFish on Jan 28, 2015, 08:09 pm

Title: WiFiUDP.remoteIp() hangs up....
Post by: dizzFish on Jan 28, 2015, 08:09 pm
Hi there,

I have a problem what is driving me crazy and i can't find any help by searching the internet and this forum for similar troubles.

I have started to write a sketch (most stuff out from tutorials) to receive and send UDP packets to/from my Arduino Due with WiFiShield. The idea is to receive commands from a java-app and perform some actions after receiving a command.

The sketch-code where the problem appears:
Code: [Select]

void loop() {
  // check if UDP Packet is available
  int packetSize = Udp.parsePacket();
  if(packetSize){
    Serial.print("INF: Received packet of size ");
    Serial.println(packetSize);
    Serial.print("INF: From ");
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(":");
    Serial.println(Udp.remotePort());
   
    // read packet into packetBuffer
    int len = Udp.read(packetBuffer, 255);
    if(len > 0) packetBuffer[len] = 0;
    Serial.println(packetBuffer);

    // send reply back
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
   }
}


here is the output of my serial:
Quote
INF: serial connection initialized (9600)
INF: WiFi Shield found
INF: trying to connect to WPA SSID 'DiZZyNet'...
INF: connected to WiFi network 'DiZZyNet'
IP Address: 10.0.0.10
MAC address: 78:C4:E:2:C:6A
INF: started UDP on Port 2390
INF: Received packet of size 2
INF: From
This is where I get struggled. It seems that Udp.parsePacket(); receives a packet of size 2, but cannot resolve the remoteIP.