Hello there,
I have looked for this issue over the Forum and Google, but I couldn't find anything suitable to my needs.
It is something pretty simple, I know, only problem is that I don't know how to make it to work>
I have Processing sending strings to Arduino via Ethernet with the Udp library.
So Processing at the moment is sending 4 groups of numbers (ints) as strings.
Each values looks pretty much like P10, Q36, R53, S8 (having one single number reads well in Processing but comes with an added '9' in Arduino).
if (n <= 0) {
fetchData();
lastTime = millis();
String ip = "192.168.1.72"; // the remote IP address
int port = 8888; // the destination port
String cone="P"+categ1;
println(cone);
udp.send(cone, ip, port ); // the message to send
myDelay(250);
String ctwo="Q"+c2;
println(ctwo);
udp.send(ctwo, ip, port ); // the message to send
myDelay(250);
String cthree="R"+c3;
println(cthree);
udp.send(cthree, ip, port ); // the message to send
myDelay(250);
String cfour="S"+categ4;
println(cfour);
udp.send(cfour, ip, port ); // the message to send
myDelay(250);
}
this way every group of values starts with an identifier, which I sould be able to read back in Arduino to identify it.
Then in Arduino I receive the package with the following code
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
Now that I have the packetBuffer I would like to extract the values so that I can use them in Arduino.
I thought I could do that by building an array:
char buff = 000;
for (int i=0; i<3; i++) {
buff[i]=buff[i+1];
}
buff[3]=Serial.read();
if (buff[0]=='P') {
r1val=int(buff[3]);
}
if (buff[0]=='Q') {
r2val=int(buff[3]);
}
if (buff[0]=='R') {
r3val=int(buff[3]); // reads the value coming from Processing related to category 3
}
if (buff[0]=='S') {
r4val=int(buff[3]);
And then I will covert the string into an int.
But for now it is not working.
Can anybody spare some little help?
Many thanks
Best
F
Thanks