Tidied and more descriptive "wwan-status" script


ouzle

Very Active Member
Joined
Jun 3, 2019
Messages
136
Location
England
I wanted to understand how to talk to the Pyra's modem so I started by studying how hns does it in the wwan-status script. I've tidied this up a bit to give more description in its output and reduced the delay a bit so it runs faster.

The original script is from the letux kernel tree and is installed on the pyra at /usr/share/pyra/scripts/letux/wwan-status

If you want to add more AT commands they are described in the datasheets on the Thales website.

Modem power usage from INA231:
Current = 8mA
Voltage = 4.065V
Power = 34.375mW
-------------
SIM status : AT^SCKS?
^SCKS: 0,2
OK
-------------
Manufacturer : AT+CGMI
Cinterion
OK
-------------
Model : AT+CGMM
PLS8-E
OK
-------------
Revision : AT+CGMR
REVISION 02.011
OK
-------------
Request International Mobile Equipment Identity (IMEI) : AT+CGSN
358000000000000
OK
-------------
International Mobile Subscriber Identity (IMSI) : AT+CIMI
+CME ERROR: SIM PIN required
-------------
PIN status : AT+CPIN?
+CME ERROR: SIM failure
-------------
Network name : AT+COPS?
+CME ERROR: SIM PIN required
-------------
Network connection : AT+WS46?
+WS46: 25
OK
-------------
Signal quality : AT+CSQ
+CME ERROR: SIM PIN required
-------------
Battery voltage : AT^SBV
^SBV: 4066
OK
-------------
Temperature : AT^SCTM=0,1
OK
-------------
Real time clock : AT+CCLK?
+CCLK: "80/01/06,04:14:02"
OK
-------------
GPS/GLONASS status : AT^SGPSC?
^SGPSC: "Engine","0"
^SGPSC: "Nmea/Freq",1
^SGPSC: "Nmea/Glonass","on"
^SGPSC: "Nmea/Output","off"
^SGPSC: "Nmea/Urc","off"
^SGPSC: "Power/Antenna","auto"
OK
-------------
Serving cell : AT^SMONI
^SMONI: 4G,1617,3,20,20,FDD,234,30,2C2F,0841400,497,9,-118,-18,LIMSRV
OK
-------------
Neighbour cell : AT^SMONP
+CME ERROR: operation not supported

Bash:
#!/bin/bash
#
# print UMTS modem status
#
# usage: wwan-status
#

# Create an array of commands and descriptions
CMDS=()
CMDS+=('AT^SQPORT?'     ); DESC+=('Port (Application, Modem, ...)')
CMDS+=('AT^SCKS?'       ); DESC+=('SIM status')
CMDS+=('AT+CGMI'        ); DESC+=('Manufacturer')
CMDS+=('AT+CGMM'        ); DESC+=('Model')
CMDS+=('AT+CGMR'        ); DESC+=('Revision')
CMDS+=('AT+CGSN'        ); DESC+=('Request International Mobile Equipment Identity (IMEI)')
CMDS+=('AT+CIMI'        ); DESC+=('International Mobile Subscriber Identity (IMSI)')
CMDS+=('AT+CPIN?'       ); DESC+=('PIN status')
CMDS+=('AT+COPS?'       ); DESC+=('Network name')
CMDS+=('AT+WS46?'       ); DESC+=('Network connection')
CMDS+=('AT+CSQ'         ); DESC+=('Signal quality')
CMDS+=('AT^SBV'         ); DESC+=('Battery voltage')
CMDS+=('AT^SCTM=0,1'    ); DESC+=('Temperature')
CMDS+=('AT+CCLK?'       ); DESC+=('Real time clock')
CMDS+=('AT^SGPSC?'      ); DESC+=('GPS/GLONASS status')
CMDS+=('AT^SMONI'       ); DESC+=('Serving cell')
CMDS+=('AT^SMONP'       ); DESC+=('Neighbour cell')

SCRIPTPATH="$(dirname "$0")"
IF="$($SCRIPTPATH/wwan-on)"

case "$IF" in
    "" )
        echo Modem Application interface not found >&2
        exit 1
        ;;

    /dev/ttyACM[0-4] | /dev/ttyUSB[0-4] )    # Neo900 / Pyra with PHS8/PLS8
        INA231=$($SCRIPTPATH/findhwmon ina231)
        if [ "$INA231" ]
        then
               pmuw=$(cat $INA231/power1_input)
               pmv=$(cat $INA231/in1_input)
               pw=$(bc <<< "scale=3; $pmuw/1000")
               pv=$(bc <<< "scale=3; $pmv/1000")

            echo Modem power usage from INA231:
            # echo "shunt resistor: $(cat $INA231/shunt_resistor) uOhm"
            # echo "across shunt voltage: $(cat $INA231/in0_input) mV"
            echo "Current = $(cat $INA231/curr1_input)mA"
            echo "Voltage = ${pv}V"
            echo "Power   = ${pw}mW"            
        fi
               
        for i in $(seq 1 $((${#CMDS[@]}-1))); do
            cmd=${CMDS[i]}
            desc=${DESC[i]}

            echo "-------------"
            echo -n "$desc : "                              
            (echo "$cmd"; sleep 0.2) | ${SCRIPTPATH}/femtocom ${IF} | sed -r '/^\s*$/d'
        done
        echo
        ;;

esac
 
Last edited:
Dumb question:

Could be possible to add some custom AT commands to run something outside the scope of the modem ?

Example:
My old phone had some AT commands to START/STOP/CONTROL the music player.
 
Why would you want to use those in a script designed to give the status of the modem and wlan chip?
I was able to control remotely my phone wirelessly just using bluetooth, without a wireless lan or even hot spot, just bluetooth.

In particular, the phone was the DUN bluetooth modem for my pc, and to have reception, the phone was always distant from the PC (and sometimes I had to leave it outside the window to have signal).
Still, even while connected to the internet, I was able to read messages directly from the PC, or checking the status of the battery, the sound level of the ring tone, and also the media player, because the phone was also connected to bluetooth stereo speakers near the PC.

It had a lot more functions with AT commands, but I never had the time to experiment with all of them... but it was "only" a feature phone... I can see a lot of use cases using remotely the Pyra at the same way, if it's possible.

EDIT:
By the way, my question wasn't directly related to this script, but just to the protocol possibilities.
 
Last edited:
Yes, digging into that script, it seems wwan-on script returns the name of the interface, and then you can squirt AT commands at it using femtocom. I wouldn't expect music player AT commands to work though, the music player if running is running on the CPU, meanwhile these AT commands are issued by the CPU and go towards the modem, so they can only control the things the modem is doing.
 
If you want to send one command directly, you can use "wwan-on" to find the modem's USB serial port, e.g.:
Bash:
user@pyra:~> sudo /usr/share/pyra/scripts/letux/wwan-on
/dev/ttyACM1

Then pipe your AT command to "femtocom" with the serial port as the argument. There's a sleep included when piping the command to hold the modem terminal open while we wait for the modem's response:
Bash:
(echo AT+CSQ; sleep 0.2) | sudo /usr/share/pyra/scripts/letux/femtocom /dev/ttyACM1

A delay of 0.2s is long enough for most commands to respond, but other commands could be slower.
 
Last edited:
Back
Top