strtok helpo plz

im looking to add a function for when the xbee receives “connected” from the remoter xbee. the servo angles come in good and write and the messagefromtx serial prints but when i try to add a function like
if messagefromyx is equal to “connected” nothing happens

#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial xbee(10, 11); // TX, RX
Servo SteerServo, MotorServo, CamServoC, CamServoD;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
char messageFromTX[numChars] = {0};
char Buttoncheck[numChars] = {0};
//ints for incoming servo data
int ServoA = 0;
int ServoB = 0;
int ServoC = 0;
int ServoD = 0;
//ints for servo write
int angleC = 0;
int angleD = 0;
boolean newData = false;
boolean Connection = false;
//============
void setup() {

  Serial.begin(9600);
  xbee.begin(9600);
  CamServoD.attach(4);
  CamServoC.attach(5);
  SteerServo.attach(6);
  MotorServo.attach(7);
}

//============

void loop() {

  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
    // this temporary copy is necessary to protect the original data
    //   because strtok() replaces the commas with \0
    parseData();
    delay(10);
    showParsedData();
    movement();
    newData = false;
  }
}

//============

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (xbee.available() > 0 && newData == false) {
    rc = xbee.read();
    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//============

void parseData() {

  // split the data into its parts
  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ",");     // get the first part - the string
  strcpy(messageFromTX, strtokIndx); // copy it to messageFromPC

  strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
  ServoA = atoi(strtokIndx);     // convert this part to an integer

  strtokIndx = strtok(NULL, ",");
  ServoB = atoi(strtokIndx);     

  strtokIndx = strtok(NULL, ",");
  ServoC = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ",");
  ServoD = atoi(strtokIndx);

}

//============

void showParsedData() {
  Serial.print(ServoA);
  Serial.print(", ");
  Serial.print(ServoB);
  Serial.print(", ");
  Serial.print(angleC);
  Serial.print(", ");
  Serial.println(angleD);
}
void movement() {
  //pan
  if (ServoC < 60 && angleC >= 0 ) {
    angleC -= 1;
  }
  if (ServoC > 100 && angleC <= 180) {
    angleC += 1;
  }
  //tilt
  if (ServoD < 60 && angleD >= 0) {
    angleD -= 1;
  }
  if (ServoD > 100 && angleD <= 180) {
    angleD += 1;
  }
  delay(50);
  MotorServo.write(ServoA);
  SteerServo.write(ServoB);
  CamServoC.write(angleC);
  CamServoD.write(angleD);

}

when i try to add a function like
if messagefromyx is equal to "connected" nothing happens

Please post your program with the test included as we don't know how you tried to do it.

I'm not currently at my home computer but when I serial print messagefromTx it prints "connected" as that what was sent from the other xbee but when. I make an if statement like
If(messagefromtx == "connected")
{
Serial.println("connected");
}
It does not work

If(messagefromtx == "connected")

To compare two C strings (null terminated character arrays) use strcmp().

The parse example in Serial Input Basics illustrates the use of strtok()

I suspect you need to use strcmp() to compare strings.

...R

I see I can stop driving myself crazy trying to find a way with strtok if there isn't one lol but I have this now I need to test

command = Serial.read();       
   } 

   if (strcmp(command, "connected")  == 0)  // test to see if the two strings are equal
   { 
      Connection = true;
      Serial.print("Connected")
   }

Referring to Reply #5

Serial.read() returns a single character. It could not possibly match "connected" which is 9 characters.

Have you studied the link I gave you ?

...R

strtokIndx = strtok(tempChars, ",");     // get the first part - the string
  strcpy(messageFromTX, strtokIndx); // copy it to messageFromPC

You have parsed the leading string into a character array called messageFromTx.

So you would want to use strcmp with that

if (strcmp(messageFromTX, "connected")  == 0)  // test to see if the two strings are equal
   { 
      Connection = true;
      Serial.print("Connected")
   }

Thank you glad to see I was on the right track at least! Is there information somewhere that defines the function and what they do as I'm trying to learn this all on my own

yes robin sorry for not responding i have studied your link thank you very much thats how i have the servos working i just could not seem to figure out how to compare more than that

Is there information somewhere

Google.

Seriously, enter "strcmp" or "strcmp example" into a Google search, and see what shows up.

is it safe to say any C++ works in Arduino?

merkzilla:
is it safe to say any C++ works in Arduino?

Is it safe to say that any english sentence can be understood by any person who speaks english?

merkzilla:
is it safe to say any C++ works in Arduino?

I suspect there are some bits that are not included in the standard Arduino compiler - but you would probably be very unlucky to stumble across them.

Carry on regardless until you get an error message.

...R

I suspect there are some bits that are not included in the standard Arduino compiler - but you would probably be very unlucky to stumble across them.

Like trying to use a float in sprintf() ?

merkzilla:
is it safe to say any C++ works in Arduino?

With v 1.6.5 of the IDE and it uses C++98 for AVR and C++11 for ARM (Due). Most of STL shouldn't really be used on micro-controllers though, due to the tight memory constraints amongst other things. How would std::chrono and std::thread even work on Arduino?

merkzilla:
I'm not currently at my home computer but when I serial print messagefromTx it prints "connected" as that what was sent from the other xbee but when. I make an if statement like
If(messagefromtx == "connected")
{
Serial.println("connected");
}
It does not work

If for some reason there is a carriage return or line feed attached to what is sent, then the comparison will fail. If you print out what is received and the printouts are on new lines, then that may be the problem.