WHOLE CODE:
////////////////////////////
#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,0X0D,0XA6,0X7F};
byte ip [] = {192,168,160,108};
byte ipReply []= {192,168,160,107};
byte dns_server [] = {192,168,215,20};
byte gateway [] = {192,168,160,1};
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13;
int buttonState = 0;
const int port1=65236;
const int port2=65236;
unsigned int localPort = port2;
unsigned int oldPort = port2;// local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
// 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:
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
Ethernet.begin(mac,ip, dns_server, gateway);
Udp.begin(localPort);
oldPort=localPort;
while (localPort==oldPort)
{
oldPort=localPort;
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*, 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);*
-
//char cArray [];*
-
int space=8;*
-
//for (int h=0; h<24; h=h+space)*
-
//{*
-
for (int j=0; j<200; j++){*
-
char cArray [j];*
-
cArray[j]=packetBuffer[j];*
-
//Serial.println(cArray[j]);*
-
//Serial.println(cArray[j],5);*
-
char c[0];*
-
c[0]=cArray[j];*
-
//float f=atof(c);*
-
//Serial.println(f,5);*
-
Udp.beginPacket(ipReply, localPort);*
-
Serial.println(j);*
-
String myString= String(j);*
-
Udp.write(myString);*
-
Udp.endPacket();*
-
}*
-
//cfloat f=atof(cArray);*
-
// Serial.println(cArray);*
-
//}*
-
// send a reply, to the IP address and port that sent us the packet we received*
-
delay (10);*
_ /*_ -
buttonState = digitalRead(buttonPin);*
-
if (buttonState==HIGH)*
-
{*
-
localPort=port1;*
-
}*
-
else localPort=port2 ; *
_ */_ -
}*
-
delay(10);*
}
}
///////////////
Specific part I have a problem with:
for (int j=0; j<200; j++){ -
char cArray [j];*
-
cArray[j]=packetBuffer[j];*
-
//Serial.println(cArray[j]);*
-
//Serial.println(cArray[j],5);*
-
char c[0];*
-
c[0]=cArray[j];*
-
//float f=atof(c);*
-
//Serial.println(f,5);*
-
Udp.beginPacket(ipReply, localPort);*
-
Serial.println(j);*
-
String myString= String(j);*
-
Udp.write(myString);*
-
Udp.endPacket();*
-
}*
///////////////////////////////
All I want to do with this code is to receive, over UDP connection a packetBuffer that has some characters (they actually contain float numbers but i won't uncode them in the arduino itself) I basically want to pass this packet buffer back through the UDP connection.
No matter how I try to send a string back through UDP.write I always get the same error: no matching function for call to 'EthernetUPD::write(String&)'
When i write stuff like UDP.write("hello world") it works fine but if i write:
String myString = String("hello world");
UDP.write (myString);
I get that error..how can that be? it makes no sense..
Thanks for any feedback (also i know the code is a mess, don't worry about all the other stuff it works fine except for this part.)