Pages: [1]   Go Down
Author Topic: Ethernet Shield UDPSendReceive not acknowledged  (Read 1239 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,

I am attempting to use the UDPSendReceive sketch with an arduino ethernet shield and it does not appear to be working. I have mounted the shield on an UNO and connected the shield to the router with an ethernet cable. When I run the DhcpAddressPrinter sketch I receive "My IP address: 192.168.0.10." in the serial monitor. I assume that this is the IP I am to enter in the "IPAddress ip(x,x,x,x);" line in the UDPSendReceive line in the sketch? So I have uploaded the following to the arduino:
Code:
/*
  UDPSendReceive.pde:
 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender
 
 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.
 
 created 21 Aug 2010
 by Michael Margolis
 
 This code is in the public domain.
 */


#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0xE2, 0x7A};

IPAddress ip(192,168,0,10);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

and run the following in processing:
Code:
/*
  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, 6000 );  // create a new datagram connection on port 6000
 udp.log( true );         // <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message 
 }
 
 void draw()
 {
 }
 
void keyPressed() {
 String ip       = "192.168.0.10"; // the remote IP address
 int port        = 8888;        // 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();   
 }

"[13-06-12 19:15:18.769 -0500] send packet -> address:/192.168.0.10, port:8888, length: 11" is the only thing output by processing and nothing appears in the serial monitor in arduino. There is no acknowledgement that the UDP was received.

In addition, tested the port 8888 on my router buy running the SharedCanvasServer and SharedCanvasClient example sketches in processing on two different machines. The UDPs seem to come through just fine on port 8888 using this method.

I am using:
Arduino UNO R3
Arduino Ethernet Shield R3
Arduino Editor v 1.0
Processing 2.0b9
Mac OSX 10.6.8

Can anyone see here what I am doing wrong?

thank you,
Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1883
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

make sure Arduino Ethernet Shield work by use netcat at Mac.

echo -n "Hello World" | nc -4u -q1 192.168.0.10 8888

check syntax please, I have not turn on my Macintosh in last 10 months.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the response sonnyyu,

If I type "echo -n "Hello World" | nc -4u -p1 192.168.0.10 8888" into terminal I receive the message "nc: bind failed: Permission denied" I assume this means it is not working?

Another thing I have found after uploading the DhcpAddressPrinter sketch onto the arduino and I ping the IP 10 times I receive "10 packets transmitted, 10 packets received, 0.0% pocket loss.... etc etc....."

But after I upload the UDPSendReceiveString onto the arduino and ping the IP 10 times "10 packets transmitted, 0 packets received, 100.0% packet loss"

Any ideas what this means? Could this be a network issue? If so any tips on how to correctly set up my network? Or is the ethernet shield not functioning?

thank you,
Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1883
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

check your firewall setting of Mac. run it as root to see if work.
« Last Edit: June 17, 2013, 10:46:33 am by sonnyyu » Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1883
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...
Another thing I have found after uploading the DhcpAddressPrinter sketch onto the arduino and I ping the IP 10 times I receive "10 packets transmitted, 10 packets received, 0.0% pocket loss.... etc etc....."

But after I upload the UDPSendReceiveString onto the arduino and ping the IP 10 times "10 packets transmitted, 0 packets received, 100.0% packet loss"

Any ideas what this means? Could this be a network issue? If so any tips on how to correctly set up my network? Or is the ethernet shield not functioning?

...

Ping use ICMP packet;-

DhcpAddressPrinter use EthernetClient, it include ICMP.
UDPSendReceiveString use EthernetUDP, it not.
I guessed it with out read through whole source code tree. You could confirm it if you want.

You should give yourself 10 more mins on Mac, if fail should start over at Windows machine and once work then back to Mac.
« Last Edit: June 17, 2013, 11:05:06 am by sonnyyu » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the tip sunnyyu! windows machine was the target! cheerio!
Logged

Vancouver Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm jealous! I've been trying to get this Processing app to run with the same Arduino UDP example, but I'm getting "nada".  I've confirmed that it is the Processing portion that isn't working.  I can use a Linux Socat UDP send to the Arduino and I see the communication.  When I try this Processing code I get a compile error, "The Constructor UDP(UDP,int) is undefined".  Also the import Link is invalid.  Hypermedia.net is no longer there.  I found the UDP library online elsewhere and have added it to my Library folder.  I think I probably haven't done this correctly, hence the compile error.  I've tried the latest Processing 2.0.1 code and then I downgraded to 1.2.1, still no go.  I believe the newest version of Processing deals with Libraries locations a little differently.

I'm only a month later at this than the previous post and I can't figure out why I'm having this trouble.  Can anyone confirm that the Arduino/Processing example will work with a "fresh" install as of today?
Logged

Pages: [1]   Go Up
Jump to: