#!/bin/bash ############################################################################ # ModemStat -- Version 2.0.3 # # Runs a series of diagnostic tests on the modem to determine what the # # - Signal strength is # - Network registration state # - SIM state (Pin Lock / Blocked / other error ) # - Service level available and Selected (GPRS/3G/etc..) # - Modem Type / IMEI / SIM Nunber/ Firmware version # # Copyright (c) 2016-2021 Andrew O'Connell and others # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ############################################################################ if [[ "$1" == "-q" ]] then OUTPUT=1 else OUTPUT=0 fi #################### MODEM VENDOR CHECK chat -Vs TIMEOUT 1 ECHO OFF "" "ATI5" "OK" >/dev/modemAT /tmp/log REGEX_SIMCOM='.*SIMCOM.*' REGEX_QUECTEL='.*Quectel.*' REGEX_SIERRA='.*Sierra.*' REGEX_NIMBELINK='.*DOB*' RESPONSE=$(/dev/modemAT /tmp/log REGEX='^([0-9]+)$' RESPONSE=`cat /tmp/log | head -n -1 | tail -n +2 | grep -v '^[[:space:]]*$'` IMEI="" if [[ $RESPONSE =~ $REGEX ]] then IMEI="${BASH_REMATCH[1]}" fi #################### SIM NUMBER # Doesn't work on Sierra Wireless Modems if [[ $MODEM != 3 ]] then chat -Vs TIMEOUT 1 ECHO OFF "" "AT+ICCID" "OK" >/dev/modemAT /tmp/log REGEX='\+ICCID: ([0-9]+)' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\+CPIN:.([a-zA-Z]*)' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\CSQ: ([0-9]*),([0-9]*)' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\+COPS:.([0-9]*),([0-9]*),"(.*)",([0-9]*)' RESPONSE=$(= 0 )) || (( $COPS1 <= 4 )) then if [[ ${OUTPUT} -eq 0 ]] then NETWORKID="${COPS3}" else NETWORKID="'${COPS3}'" fi fi else if [[ ${OUTPUT} -eq 0 ]] then NETWORKID="** Information Not Available **" else NETWORKID="NOTAVAILABLE" fi fi #################### NETWORK REGISTRATION STATE chat -Vs TIMEOUT 1 ECHO OFF "" "AT+CREG?" "OK" >/dev/modemAT /tmp/log REGEX='\+CREG: ([0-9]*),([0-9]*)' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\+QNWINFO: "(.+)","(.+)","(.+)",' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\+CNSMOD: ([0-9]),([0-9])' RESPONSE=$(/dev/modemAT /tmp/log REGEX='\*CNTI: ([0-9]+),([a-zA-Z]+)' RESPONSE=$(/dev/modemAT /tmp/log echo -e "Modem Specification : \n" cat /tmp/log | head -n -1 | tail -n +2 | grep -v '^[[:space:]]*$' fi echo fi