I am sending string from Arduino to Arduino via Xbee. I don't know if this is the proper way to do it and I am open to know any feedbacks. Here is what I do, I am sending something from A and it looks like:
0|302|306|1|222|291|303|1|0|1|1|1|1
Now, B is getting this string and trying to analyze it. Here is my code:
if (Serial.available() > 0) {
char incomingString = Serial.read();
Serial.print(incomingString);
Serial.println(":");
It doesn't read the string but some single character. The line "char incomingByte = Serial.read();" should be the problem and I am not sure what is *sign for. Please help if anyone knows how to do this? Thanks a lot!
______________________________________________________________________FYI
I use this function to break the string into variable I need.
char* subStr (char* str, char *delim, int index) {
char *act, *sub, *ptr;
static char copy[MAX_STRING_LEN];
int i;
strcpy(copy, str);
for (i = 1, act = copy; i <= index; i++, act = NULL) {
//Serial.print(".");
sub = strtok_r(act, delim, &ptr);
if (sub == NULL) break;
}
return sub;
}
And this always works while testing:
Serial.println(subStr(incomingByte, "|", 1));
Serial.println(subStr(incomingByte, "|", 2));
Serial.println(subStr(incomingByte, "|", 3)); // and so on
It breaks to string into what I need.