Hi All,
I'm trying to develop some SMS controlled events using the wondrous arduino. I'm sending without problems using 'Serial.print' with AT commands and happy that I can grab SMS received data and assign the data to a string variable. I can also parse the info to split it into sections by de-limiting according to any particular character. What I'm having trouble with is after spiltting the data, grabbing the two bits of meaningful data and assigning them to string variables. Has anyone any ideas or solutions - some example code would be nice?
Below is my idea of grabbing two items of data using a for loop with conditioning inside that assigns two string variable names to the two delimited items of data that are grabbed by a with statement. If what I'm trying to do is crazy please say as I have been away from coding for some years.
Any feedback would be very useful. If anyone would use a different approach I would also be interested.
thanks in anticipation - Tim.
/*
* GM862_SMS_Trials
* by Tim
*
* Program to look at string from sms and delimit to find meaningful data.
* For this purpose the data is in the form of string variable held as a constant
* Use is made of delimiting to seperate the items within the message
*
*/
char SMS[] = "+cmgl: 1,'REC UNREAD','+449999999999'<CR>pin11<CR>OK"; // SMS string
void setup()
{
char *p = SMS; // pointer to SMS string
char *str;
char *str1;
char *str2;
int i=0;
Serial.begin(9600);
Serial.flush();
while ((str = strtok_r(p, "+", &p)) != NULL) // delimiter is the plus sign - gives two blocks of
// of delimited data
Serial.print(str); // print statement for debugging
for (i=0;i<2;i++) // small two stage loop to assign variables to two 'lumps' of data
{
if(i==0) // condition looks at iteration to assign different variable names
{
Serial.print("in the loop #1"); // print statement for debugging
strcpy(str1,str); // copies str to new variable name
}
else if(i==1)
{
Serial.print("in the loop #2"); // print statement for debugging
strcpy(str2,str); // copies str to new variable name
}
else
{
Serial.print(str); // print statement for debug purposes
}
}
Serial.print("got here!"); // print statement for debugging
Serial.print(str2); // prints secons item of data
}
void loop()
{
}