Arduino recieving but not sending UDP

Hello

I usually find answers to my problems without having to reach out and ask however this one has got me stumped.

Firstly... I am using up to date versions of Arduino IDE and Processing on a Mac running 10.8.5.

I am trying to set up an Arduino Uno R3 to send messages via UDP with an Ethernet shield R3 (Wiznet W5100). I had some trouble with this so stepped back to working with the example files provided with the UDP library (originally Hypermedia.net). The example does not work fully for me. I have found other examples on the forums where people are having similar problems but not exactly the same.

Basically.... The Arduino receives the UDP message from the Processing sketch. It then sends its text via serial to the Arduino serial monitor all good. It however does NOT then send the "acknowledged" UDP message back to processing. The tx light is flashing so I assumed something is being sent out....

I have tried the connection with PacketSender and Wireshark and do not seem to be getting the UDP message back on these either....

The code is just the code within the example file....

Any advice here would be greatly appreciated... Apologies in advance if my forum etiquette is bad... this is a first for me.

Add some error checking to the reply send.

    // send a reply, to the IP address and port that sent us the packet we received
    if(Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()) == 0) Serial.println("beginPacket failed");
    Udp.write(ReplyBuffer);
    if(Udp.endPacket() == 0) Serial.println("reply send failed");

Udp.beginPacket will fail if there is a problem with the destination IP or port.
Udp.endPacket will fail if the first device en route to the destination does not accept the packet.

Thank you for the swift reply.... I will give this a go tomorrow. :slight_smile:

If it is Udp.endPacket that is failing, check your network settings like netmask and gateway.

Ok...Firstly, thank you SurferTim for your help... I have tried the above error checking code and it is showing that the problem seems to be with Udp.endPacket. Could you please possibly suggest what I might need to change within the network settings? Do the netmask and gateway need to be specified within Ethernet.begin to be the same as on the host computer?......Or am I completely lost? .... :-/

The netmask and gateway must be the same if the two are on the same localnet.

If your localnet has a dhcp server, run this code. It will show the subnet mask and gateway for the localnet.

#include <SPI.h>
#include <Ethernet.h>

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

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else {
      Serial.println(Ethernet.localIP());
      Serial.println(Ethernet.subnetMask());
      Serial.println(Ethernet.gatewayIP());
 }
}

void loop() {
}

Right...tried that and after a minute or so it just comes up with the "failed" serial message....

Put the Serial.println(Ethernet.subnetMask()); etc code in to the other sketch and it doesn't fail.... and I am getting the IP addresses coming up in the serial monitor... They do differ from the subnet mask within System Preferences > Network Preferences.

Then you must specify the subnet mask and gateway in the begin call.

Done!! ... Thank you very much for your help!! That would have taken me years without you.