Here is my code. The incoming string is "*CRB12344,Temp25,Humidity55,CC5#"
I am unable to get value of Temp which is 25 and Humidity which is 55 and CC which 5. It only display the value of CR i.e B12344 (in this case). May be issue with strtok function?
String inputString = "";
boolean stringComplete = false, StartCapturing = false;
char inData[50];
char inChar, IncomingWeight;
char IncomingString[50];
const int httpPort = 80;
char *i, *k,*p;
String CardID;
int Temprature, Humidity, TC, CC;
byte SendData = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
serialEvent();
if (stringComplete)
{
inputString.toCharArray(IncomingString, 50);
Serial.println();
Serial.println(IncomingString);
i = strstr(IncomingString, "CR");
{
if (i)
{
p = i+2;
CardID = strtok(p, ",");
Serial.print("Card Number :");
Serial.print(CardID);
Serial.println();
}
}
i = strstr(IncomingString, "Temp");
{
if (i)
{
Temprature = strtoul(i + 4 , NULL, 10);
Serial.print("Temprature :");
Serial.print(Temprature);
Serial.println();
}
}
i = strstr(IncomingString, "Humidity");
{
if (i)
{
Humidity = strtoul(i + 8 , NULL, 10);
Serial.print("Humidity :");
Serial.print(Humidity);
Serial.println();
}
}
i = strstr(IncomingString, "TC");
{
if (i)
{
TC = strtoul(i + 2 , NULL, 10);
Serial.print("Total Count :");
Serial.print(TC);
Serial.println();
}
}
i = strstr(IncomingString, "CC");
{
if (i)
{
CC = strtoul(i + 2 , NULL, 10);
Serial.print("Current Count :");
Serial.print(CC);
Serial.println();
}
}
stringComplete = false;
inputString = "";
delay(10);
}