I am currently gathering info from a BLE device. I made a thread earlier where I successfully split a string consisting of 5 letters to their unique chars.
However from this BLE device i will also send some different information from time to time where I send 3 different values with a space after each one. So for example looking like this:
-0.1 0.51 0.07
So what I want to do now is to store this three numbers in different doubles and what I have done so far is this:
First i store the recieved message:
String recievedMessage;
recievedMessage += (char)BTLEserial.read();
Now I have to determine if the value sent is the 5 letters or if it is the numbers with a space between each value.
if (recievedMessage.length() > 5) //so if the recievedmessage is more than 5 words then it is the 3 values that is being sent.
{
char * charTheMessage = recievedMessage.c_str();
char *str;
str = strtok(charTheMessage, " ");
double one = str[0];
double two = str[1];
double three = str[2];
Serial.println (one);
Serial.println (two);
Serial.println (three);
}
if (recievedMessage.length() == 5)
{
//http://arduino.stackexchange.com/questions/36227/how-can-i-split-a-string-into-multiple-parts/36237?noredirect=1#comment72313_36237
//Here I split the letters into 5 different values if the value sent is 5.
}
But this values do not come out right when I print them in the serial monitor. I have also read that strtok is not reliable when data is sent fast so is strtok the right way to go you think?