Posting images of text just makes it harder to help you. If I want to write some code to try to decipher that line, I would have to type it in. What a pain. If you post the text I could copy and paste.
Please read the forum guidelines to see how to properly post code.
This is the complete code, I was modifying it but it prints the 3 variables and does not save them separately since as I mentioned before I have never worked with the strtok function
#include <WaspXBee802.h>
// define variable
uint8_t error;
char var1[10], var2[10], var3[10];
void setup()
{
// init USB port
USB.ON();
USB.println(F("Receiving example"));
// init XBee
xbee802.ON();
}
void loop()
{
// receive XBee packet (wait for 10 seconds)
error = xbee802.receivePacketTimeout( 10000 );
// check answer
if( error == 0 )
{
char* data = strtok( (char*)xbee802._payload, ":");
while(data != NULL)
{
data = strtok(NULL, ":");
sprintf(var1,"%s",data);
USB.println (var1);
}
}
else
{
// Print error message:
/*
* '7' : Buffer full. Not enough memory space
* '6' : Error escaping character within payload bytes
* '5' : Error escaping character in checksum byte
* '4' : Checksum is not correct
* '3' : Checksum byte is not available
* '2' : Frame Type is not valid
* '1' : Timeout when receiving answer
*/
USB.print(F("Error receiving a packet:"));
USB.println(error,DEC);
}
}
Esto es lo que imprime
J#
Receiving example
Error receiving a packet:1
26.73#HUM
38.6#PRES
91341.33#
It seems clear the message consists mostly of name/value pairs. Each pair is delimited by '#', and the name and value within each pair are delimited by ':'. The sensible way to parse that is:
Process the entire string using strtok, with '#' as the delimiter, to extract all of the name/value pairs. Save pointers to ALL of the strings returned by strtok, to be used in step #2.
Process ALL the strings obtained from #1 above, and use strtok again, with ':' as the delimiter, to separate the individual name/value pairs.
Process each name/value pair by examining the name to find the names you care about, and retrieve the values for those names, ignoring/discarding all the others.
That makes for a very simple, step-by-step parsing of all variables that can be easily extended to add new name/value pairs as needed.