Search code examples
arduinogsm

Arduino GSM library phonenumber position


Using the Arduino GSM library to get authenticated call and sms. I want to store position (one byte) of the authorized phone number not the phonenumber (many bytes).

But GetAuthorizedSms do not give me position, just phone number


Solution

  • If you look in sms.cpp you can see that they use gsm.ComparePhoneNumber(i, ph) to compare the phonenumber on position i with the one you have.

    byte get_phonenr_position(char *ph)
    {
        byte i;
        for(i = 1; i <= 20; i++)
            if (gsm.ComparePhoneNumber(i, ph))
                return i;
        return 0;
    }
    

    should work but is not so efficient as you have to ask the module via the serial interface. I have added a variable last_authorized to the SMSGSM (and CallGSM) class:

    sms.cpp:
                         // phone numbers are identical
                         // authorization is OK
                         // ---------------------------
    +                    last_authorized = i;
                         ret_val = GETSMS_AUTH_SMS;
                         break;  // and finish authorization
                     }
    sms.h:
          char GetAuthorizedSMS(byte position, char *phone_number, char *SMS_text, byte max_SMS_len,
                               byte first_authorized_pos, byte last_authorized_pos);
         char DeleteSMS(byte position);
    +    // set by CallStatusWithAuth
    +    byte last_authorized;
    };
    

    and read that variable from my SMSGSM instance. (For CallGSM I have done the same).