sending udp data with Wifi shield using WifiUDP class

Hey all
I’m working on a project that will have a motion sensor outside hooked up to an arduino uno talking to a computer inside running an OpenFrameworks application. I’m using the WiFi shield and trying to send udp packets to the OF app and having some issues.

This is what I have running on the board, its a slightly edited version of the udp send/receive example

#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>

int status = WL_IDLE_STATUS;
char ssid[] = "MrKobblepot"; //  your network SSID (name) 
char pass[] = "ObaaYaaJuni1998";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

IPAddress remotIp(192, 168, 0, 22);
byte mess = 'a';

WiFiUDP Udp;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  int portUp = Udp.begin(9000);  
  Serial.println(portUp);//prints 1
}

void loop() {
  delay(1000);
  sendPacket(remotIp);
  delay(1000);
}

void sendPacket(IPAddress& remote){
  int beganPacket = Udp.beginPacket(remote, 9000);//ip address of laptop at home
  int sentByte = Udp.write(mess);
  int endPacketRight = Udp.endPacket();
  Serial.print("began packet: ");
  Serial.println(beganPacket);
  Serial.print("sent byte: ");
  Serial.println(sentByte);
  Serial.print("sent packet successful: ");
  Serial.println(endPacketRight);
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

and the serial monitor prints this out :

Attempting to connect to SSID: MrKobblepot
Connected to wifi
SSID: MrKobblepot
IP Address: 192.168.0.30
signal strength (RSSI):-53 dBm

Starting connection to server…
1
began packet: 1
sent byte: 1
sent packet successful: 0

with the last 3 messages repeating every second. I’m not sure why this could possibly be failing. cuz i’m not getting anything on the OF end either and that side is up and running. I tested it earlier by building an OF server and OF client and that worked. I also built a Processing OSC client and OF Server and that worked too.

Any Ideas?

This means the send failed. That normally means the wifi router refused to take the packet.

sent packet successful: 0

Are you using IDE v1.0.5? Have you upgraded the wifi shield firmware? I tested the UDP and TCP client sections of the wifi library, and they work ok with the upgrade. The server does not, but that is a different story.

I have v1.05 but no i havent upgraded the firmware I just picked the shield up at a store this weekend and tried it. I'll try upgrading the firmware and see if that helps. Thanks for bringing that to my attention.

The firmware upgrade is a bit of a pain. Here is my experience.
http://forum.arduino.cc/index.php?topic=200784.msg1490376#msg1490376
I forgot to mention in that about installing the jumper on the 2 pins to program it. I did that after installing the usb cable into the shield. Insure to remove it when complete.

Hmm I'm pretty sure got the firmware installed now (though i dont have a ftdi adapter to check) and I reuploaded the sketch and I'm still having the same issues. Is it possible that my home internet router is just refusing to accept the packets?

Edit: I must have installed older firmware or something i just re installed it and looks like everything is up and running!.

Thanks!

You don't need the ftdi adapter to check the firmware version now. You can do it with your sketch. I check in setup after checking if the shield is present.

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println(F("WiFi shield not present")); 
    // don't continue:
    while(true);
  } 

  // check firmware version
  Serial.print(F("Firmware version: "));
  Serial.println(WiFi.firmwareVersion());

awesome thanks for showing me that!