Thank you for everyone's help in trying to find a solution. This library I'm working with was prewritten and is one of the most buggy hardware libraries I've had the misfortune to use. I have now solved to problem by reusing the response parsing code from the library and rewriting my own sequence to return the number using a completely different approach. Many Thanks again!
I am currently attempting to understand how this function works and am struggling. I want to be able to access the 'number' variable in my main function but currently when I do that I get nothing (as in "") when I try to printout the variable with:
Serial.println(incomingNumber);
I am currently preassigning the number as:
char incomingNumber[14];
at the top of my project file. With a class initial setup of:
DFRobot_SIM808 sim808(&Serial);
I'm then later calling the function like this:
if(sim808.isCallActive(incomingNumber)){Serial.println(incomingNumber);}
This seems like I'm currently making a fundamental error in understanding data types but I'm a bit lost so any help would be really appreciated.
I havent included my entire project here because its currently quite long and spread across both the main and some library files but if anyone needs more info please ask and I'll upload the extras.
The function from the library I'm working with is included below:
bool DFRobot_SIM808::isCallActive(char *number)
{
char gprsBuffer[46]; //46 is enough to see +CPAS: and CLCC:
char *p, *s;
int i = 0;
sim808_send_cmd("AT+CPAS\r\n");
/*Result code:
0: ready
2: unknown
3: ringing
4: call in progress
AT+CPAS --> 7 + 2 = 9 chars
--> 2 char
+CPAS: 3 --> 8 + 2 = 10 chars
--> 2 char
OK --> 2 + 2 = 4 chars
AT+CPAS
+CPAS: 0
OK
*/
sim808_clean_buffer(gprsBuffer,29);
sim808_read_buffer(gprsBuffer,27);
//HACERR cuando haga lo de esperar a OK no me har閾哸 falta esto
//We are going to flush serial data until OK is recieved
sim808_wait_for_resp("OK\r\n", CMD);
//Serial.print("Buffer isCallActive 1: ");Serial.println(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CPAS:"))) {
s = s + 7;
if (*s != '0') {
//There is something "running" (but number 2 that is unknow)
if (*s != '2') {
//3 or 4, let's go to check for the number
sim808_send_cmd("AT+CLCC\r\n");
/*
AT+CLCC --> 9
+CLCC: 1,1,4,0,0,"656783741",161,""
OK
Without ringing:
AT+CLCC
OK
*/
sim808_clean_buffer(gprsBuffer,46);
sim808_read_buffer(gprsBuffer,45);
//Serial.print("Buffer isCallActive 2: ");Serial.println(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CLCC:"))) {
//There is at least one CALL ACTIVE, get number
s = strstr((char *)(s),"\"");
s = s + 1; //We are in the first phone number character
p = strstr((char *)(s),"\""); //p is last character """
if (NULL != s) {
i = 0;
while (s < p) {
number[i++] = *(s++);
}
number[i] = '\0';
}
//I need to read more buffer
//We are going to flush serial data until OK is recieved
return sim808_wait_for_resp("OK\r\n", CMD);
}
}
}
}
return false;
}
char incomingNumber[14];
"