Programmatically read SIM phone number

Is that possible?

Hello Nino,

Thank you so much for sharing your question.

Please find answer below:

Yes it is possible. Please refer to the modem documentation from U-Blox:

On page 84 find Network service:

Subscriber number +CNUM: Returns the MSISDNs related to this subscriber. If the subscriber has different MSISDN for different services, each MSISDN is returned in a separate line.

MSISDN is read from the SIM.

Hope this helps!

Thanks for your clear reply Nachoherrera.

As I am not using AT commands in my program, only MKRGSM library functions, is there an alternative way or I must implement AT communication with the module?

You really can’t use AT commands directly in your library with any ease. I had some special functions I needed for my program so I edited the GSM library. First save your library in case you screw up. Open GSMModem.cpp and go to the bottom. Add something like this:
String GSMModem::getphnum() //This part goes into GSMModem.cpp
String _phnum;


MODEM.waitForResponse(100, &_phnum);

if (_phnum.startsWith("+CNUM: ")) {
} else {
_phnum = “”;
return _phnum;


String getphnum(); //This part goes into GSMModem.h

Next go to GSMModem.h and add the final line at the bottom of the list of commands before the ENDIF:
When you recompile it will now have a new command getphnum() which will return a string with all but the +CNUM: part. You can figure out how to trim it based on your personal needs. Be sure to create a string and assign it to that string when you call the function like string phnum = getphnum();

In fact I was able to send commands and get responses by first setting up the u-blox:

digitalWrite(GSM_RESETN, HIGH);
digitalWrite(GSM_RESETN, LOW);

and then sending the command:

String res = String("");
while (SerialGSM.available()) {
  char c =;
  res += c;

and it worked well but I had to stop using it because it turns that when I was writing the flash (using it as eeprom) and then going through above code, the board just hangs and needed a reset.

Since all I needed was to fetch the SIM phone number, I am now sending SMS from the board to a VOIP number which reviles the number.

Thanks anyways, I may go back to try your suggestion.