How do I send UDP messages via Wi-Fi?

Hello,
My task is to send UDP messages from my pc to the arduino uno (connected to the wifi shield) and back. I'm not sure how I'm suppose to do this. I connected my arduino board to wifi using the shield, but I don't know what to do next. Please help me find a solution.

Thank you.

connected to the wifi shield

The WiFi shield? There are lots of WiFi shields.

Using which version of the IDE?

Arduino Uno Wifi Shield R3... Arduino 1.0.5 software

Here is what my code looks like so far:

/*
WiFi UDP Send and Receive String

This sketch wait an UDP packet on localPort using a WiFi shield.
When a packet is received an Acknowledge packet is sent to the client on port remotePort

Circuit:

  • WiFi shield attached

created 30 December 2012
by dlf (Metodo2 srl)

*/

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

int status = WL_IDLE_STATUS;
char ssid[] = "GTvisitor"; // your network SSID (name)
int keyIndex = 0; // your network key Index number (needed only for WEP)

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

char packetBuffer[255]; //buffer to hold incoming packet

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);

// 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:
Udp.begin(localPort);
}

Hello,
My task is to send UDP messages from my pc to the arduino uno (connected to the wifi shield) and back. I'm not sure how I'm suppose to do this. I connected my arduino board to wifi using the shield, but I don't know what to do next. Please help me find a solution.

Thank you.

HELP PLEASE

Help please!

It should go something like this if the UDP listener is 192.168.0.2 on port 8888.

IPAddress remoteIP(192,168,0,2);
int remotePort = 8888;

strcpy(packetBuffer,"This is a test");

Udp.beginPacket(remoteIP,remotePort);
Udp.write(packetBuffer,strlen(packetBuffer));
Udp.endPacket();

Where am I suppose to put that in the code?

You did not include a loop() function, so there was really nowhere in your code to put it. But for a test, this should do. It sends a udp packet once a second. It does not listen for a response.

void loop() {
  IPAddress remoteIP(192,168,0,2);
  int remotePort = 8888;

  strcpy(packetBuffer,"This is a test");

  Udp.beginPacket(remoteIP,remotePort);
  Udp.write(packetBuffer,strlen(packetBuffer));
  Udp.endPacket();

  delay(1000);
}

Ok. It's saying these errors:

WiFiUdpSendReceiveString.ino: In function 'void loop()':
WiFiUdpSendReceiveString:71: error: invalid conversion from 'char*' to 'const uint8_t*'
WiFiUdpSendReceiveString:71: error: initializing argument 1 of 'virtual size_t WiFiUDP::write(const uint8_t*, size_t)'

and it won't let me upload

Ok. It's saying these errors:

So, line 71 needs a cast. What is line 71?

I forgot about the uint_8t*. That is a byte type, not char. This usually fixes it.

// change this
char packetBuffer[255]; //buffer to hold incoming packet
// to this
byte packetBuffer[255]; //buffer to hold incoming packet

Or you can cast it as a (byte*).