How to determine if SIM card installed

Home Forums General How to determine if SIM card installed

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30785
    William Laing
    Participant

    various Conduit models
    various firmware levels

    Good Day –

    Is there a way to determine if a SIM card is installed from software (i.e. mts-io-sysfs, Node-RED, REST API, etc.)?

    Thanks in advance for your help.

    William

    #30786
    Jeff Hatch
    Keymaster

    Hello Wiliam,

    Here’s some C++ example code that detects the card on the current mPower devices:

    
    const char * const MEDIACARDDIRMLINUX3 = "/media/card";
    const char * const MEDIACARDDIRMLINUX4 = "/run/media/mmcblk0p1";
    const char * const PROCMOUNTS = "/proc/mounts";
    
    bool isSDCardInserted()
    {
        std::ifstream procMounts(PROCMOUNTS);
        std::string line;
    
        if (!procMounts.good())
        {
            return false;
        }
    
        while(!procMounts.eof())
        {
            line.clear();
            std::getline(procMounts, line);
            //std::cout << line << std::endl;
    
            std::size_t found = line.find(MEDIACARDDIRMLINUX3);
            std::size_t found4 = line.find(MEDIACARDDIRMLINUX4);
            if ((found != std::string::npos) || (found4 != std::string::npos))
            {
                return true;
            }
        }
    
        return false;
    }
    

    It’s really just using /proc/mounts and looking for the right string for the media card mount. Probably could be done in a shell script in the same amount of code or less.

    Jeff

    #30787
    William Laing
    Participant

    That’s perfect, Jeff, thank you! Just what we need …

    Have a great day!

    William

    #30788
    Jeff Hatch
    Keymaster

    William,

    Wait! The above is for SD card. Sorry about my misunderstanding your question. There are AT commands that are available to detect the SIM. One way to do it on an mPower is to use the radio-query utility:

    root@mtcap:/home/admin# radio-query –sim-status
    {
    “isSimInserted” : false
    }

    It returns whether the SIM is inserted/detected. This is an abstracted higher level implementation that works for all the radios supported by mPower software. To do this for a Quectel or Telit radio specifically implemented on your own it is different.

    For Quectel you would use the “AT+QSIMSTAT?” command and parse its output.

    For Telit you would use the “AT#SIMDET?” command and parse its output.

    Jeff

    • This reply was modified 3 years, 10 months ago by Jeff Hatch.
    #30790
    William Laing
    Participant

    Thanks, Jeff, no worries – I hadn’t begun designing/coding yet.

    Yes, AT commands make a lot of sense.

    Have a great day!

    William

    #30953

    Glad to know more about it. I’m a newbie here. I didn’t know how to determine if a sim card installed. But after reading your guidelines I got useful info. Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.