3

gprsTest.isCallActive(PHONE_NUMBER) return always 0 even phone is ringing. Acording to GPRS_Shield_Arduino.cpp from this library return 0 for ready, 2 for unknown, 3 for ringing, 4 for call in progress. What am I doing wrong? AT commnads are here .

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>


#define PIN_TX    7
#define PIN_RX    8
#define BAUDRATE  9600
#define PHONE_NUMBER "003xxxxxxxxxx"
#define MESSAGE  "Temp is high"

GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate

void setup() {
  Serial.begin(9600);

  // code 

}

void loop() {

// ..code..


  if (temp>35) {
    call_number();
  }

// ..code..

}

void call_number() {
  Serial.println(gprsTest.isCallActive(PHONE_NUMBER));// return 0 that is ok
  Serial.println("Start to call...");
  gprsTest.callUp(PHONE_NUMBER); // It calls and phone is ringing 
  delay(4000);
  Serial.println(gprsTest.isCallActive(PHONE_NUMBER)); // It return again 0 when phone is ringing

}

Edit 1: After Ouss4 answer as he said gprsTest.isCallActive(PHONE_NUMBER) return 0 or 1. How can I modify this library or build my own function to check if call is active(ringing)?

Edit 2: I changed to

char number[15] = "00306912345678";
char numberToCallActive[15] = "00306912345678";
...
setup(){
...

...
}
void call_number(){
  Serial.println(F("Before call"));
  Serial.println(gprsTest.isCallActive(numberToCallActive)); // return 0 , I uncomment Serial.print on cpp to print gprsBuffer
  Serial.println(F("start to call ... "));
  gprsTest.callUp(number);
  Serial.println(F("SUCCESS"));
  Serial.println(F("When phone is ringing"));
  Serial.println(gprsTest.isCallActive(numberToCallActive)); return 0 , I uncomment Serial.print on cpp to print gprsBuffer
  Serial.println(F("Again when phone is ringing"));
  Serial.println(gprsTest.isCallActive(numberToCallActive));return 0 , I uncomment Serial.print on cpp to print gprsBuffer
  Serial.print("\n");
}

output:

    Before call
    Buffer isCallActive 1: AT+CPAS
    +CPAS: 0

    OK

    0
    start to call ... 
    SUCCESS
    When phone is ringing
    Buffer isCallActive 1: ATD00306912345678;
    AT+CPAS

    0
    Again when phone is ringing
    Buffer isCallActive 1: 
    0

2 Answers2

1

Well, if you take a look a the code of the isCallActive() function, you'll see that it returns a boolean (0 or 1) not 2, 3, 4.

What actually returns these numbers, depending on the status of the call, is the AT command AT+CPAS. And the library doesn't take under consideration all the returns of AT+CPAS.

isCallActive(), as it is implemented, will return 1 if the phone is ringing.

You can write your own and parse the return value.


After reading the code carefully I found out that I was actually mistaken about the return of the function. I edited my answer, the function should return 1 if the phone is ringing.

However you've got a serious problem on how you are calling the function.

The function tries to get the number too and store it in the parameter you send (isCallActive(char *number)), however you are sending a string literal, then the function tries to modify it, and attempting to modify a string literal results in an undefined behavior.

That's what's happening when you call isCallActive with PHONE_NUMBER

Try to call it properly.

That should give something like this:

#define MAX_LEN_NUMBER 10 // or whatever the max number is.

....

char numberToCallActive[MAX_LEN_NUMBER] = "";

void setup()
{
  ....
}

void loop()
{
 ...
 isCallActive(numberToCallActive);
 ....
}

You can then use this variable to check if actually the number ringing is the number you called.

Ouss4
  • 479
  • 4
  • 11
  • You mean I have to write my own function? Or to modify the library? I cant handle AT commands very well that is why I use this library –  Jul 03 '16 at 20:41
  • The license of the library allows you to modify it if you'd want to. Actually there isn't a lot of work to do, you just need to add the logic for the other returns of AT+CPAS. If you only need that for testing, you can directly send this command to your shield through the Serial Monitor and see the result. – Ouss4 Jul 03 '16 at 20:44
  • It looks like AT+CPAS is not returning anything convenient when you are calling. Uncomment line 414 to confirm that the code isn't entering the `if` statement. Try to send AT+CPAS from the serial monitor. When you perform a call open Serial Monitor and just send AT+CPAS, remove all the isCallActive part (make sure that "Both NL & CR" and correct baudrate are selected). – Ouss4 Jul 04 '16 at 17:54
  • Line 414 was uncommented. –  Jul 04 '16 at 17:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116395/discussion-between-ouss4-and-dimitris). – Ouss4 Jul 04 '16 at 17:59
0

Should you use the AT+CIND command? to get the call states.

Example.

IN+CIND?
-> +CIND: 5,3,1,1,1,0,0

Where 5,3,1,1,1,0,0 indicates that the call has been answered.

Use the command AT+CIND? in conjunction with AT+CLCC for more information

Ronald Coarite
  • 4,460
  • 27
  • 31