c++arduinogsmgprs

How to check if a call is active on SIM800L for Arduino?


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

Solution

  • 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.