How to determine if SIM card installed
Tagged: sim ppp aep conduit cellular
- This topic has 5 replies, 3 voices, and was last updated 5 years, 3 months ago by
dicksonemily290@gmail.com.
-
AuthorPosts
-
June 22, 2020 at 3:12 pm #30785
William Laing
Participantvarious Conduit models
various firmware levelsGood 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
June 22, 2020 at 4:08 pm #30786Jeff Hatch
KeymasterHello 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
June 23, 2020 at 8:42 am #30787William Laing
ParticipantThat’s perfect, Jeff, thank you! Just what we need …
Have a great day!
William
June 23, 2020 at 10:13 am #30788Jeff Hatch
KeymasterWilliam,
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 5 years, 4 months ago by
Jeff Hatch.
June 23, 2020 at 11:22 am #30790William Laing
ParticipantThanks, Jeff, no worries – I hadn’t begun designing/coding yet.
Yes, AT commands make a lot of sense.
Have a great day!
William
July 15, 2020 at 9:52 pm #30953dicksonemily290@gmail.com
ParticipantGlad 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!
-
This reply was modified 5 years, 4 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.