UDP Example?

Howdy,

I’m trying to receive a UDP stream from a remote computer with my Arduino Duemilanove. I found the documentation on UDPSendReceiveString, which includes an example. However, the example doesn’t compile (with arduino019).

Here’s the example code:

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <Udp.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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1,177 };

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

// the next two variables are set when a packet is received
byte remoteIp[4];        // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port

// 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

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.available(); // note that this includes the UDP header
  if(packetSize)
  {
    packetSize = packetSize - 8;      // subtract the 8 byte header
    Serial.print("Received packet of size ");
    Serial.println(packetSize);

    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    Udp.sendPacket( ReplyBuffer, remoteIp, remotePort);
  }
  delay(10);
}

Here’s the error code when I try to compile:

Udp_example.cpp: In function 'void loop()':
Udp_example:56: error: invalid conversion from 'char*' to 'uint8_t*'
Udp_example:56: error: initializing argument 1 of 'int UdpClass::readPacket(uint8_t*, uint16_t, uint8_t*, uint16_t*)'
Udp_example:56: error: invalid conversion from 'unsigned int' to 'uint16_t*'
Udp_example:56: error: initializing argument 4 of 'int UdpClass::readPacket(uint8_t*, uint16_t, uint8_t*, uint16_t*)'

It obviously has something to do with variables in the readPacket() function. Any ideas on how to fix?

Hi, I tried your code on version 0021 in Ubuntu and got non errors ...

JP