ModemMonitor: Periodically check whether the modem is still alive, reset it if not

Signed-off-by: Stacy Harper <contact@stacyharper.net>
master
Maarten van Gompel 3 years ago committed by Stacy Harper
parent 13b29f7139
commit edc48a01d2
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65
  1. 4
      configs/sudo/modem
  2. 1
      scripts/core/sxmo_appmenu.sh
  3. 2
      scripts/core/sxmo_statusbar.sh
  4. 33
      scripts/modem/sxmo_modemmonitor.sh
  5. 20
      scripts/modem/sxmo_modemmonitortoggle.sh

@ -0,0 +1,4 @@
ALL ALL=NOPASSWD: /sbin/rc-service eg25-manager restart
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager stop
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager start
ALL ALL=NOPASSWD: /sbin/rc-service modemmanager restart

@ -140,6 +140,7 @@ programchoicesinit() {
$icon_aru Brightness ^ 1 ^ sxmo_brightness.sh up $icon_aru Brightness ^ 1 ^ sxmo_brightness.sh up
$icon_ard Brightness ^ 1 ^ sxmo_brightness.sh down $icon_ard Brightness ^ 1 ^ sxmo_brightness.sh down
$icon_phn Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh $icon_phn Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh
$icon_phn Modem Reset ^ 1 ^ sxmo_modemmonitortoggle.sh reset
$icon_inf Modem Info ^ 0 ^ sxmo_modeminfo.sh $icon_inf Modem Info ^ 0 ^ sxmo_modeminfo.sh
$icon_phl Modem Log ^ 0 ^ sxmo_modemlog.sh $icon_phl Modem Log ^ 0 ^ sxmo_modemlog.sh
$icon_wif Wifi $( $icon_wif Wifi $(

@ -48,6 +48,8 @@ update() {
MODEMMON="" MODEMMON=""
elif [ connected = "$MODEMSTATE" ]; then elif [ connected = "$MODEMSTATE" ]; then
MODEMMON="" MODEMMON=""
elif [ failed = "$MODEMSTATE" ] || [ disconnected = "$MODEMSTATE" ]; then
MODEMMON=""
else else
MODEMMON="" MODEMMON=""
fi fi

@ -295,6 +295,10 @@ mainloop() {
elif echo "$newstate" | grep "int32 11"; then elif echo "$newstate" | grep "int32 11"; then
echo connected > "$MODEMSTATEFILE" echo connected > "$MODEMSTATEFILE"
#3G/2G/4G available #3G/2G/4G available
elif echo "$newstate" | grep "int32 -1"; then
echo failed > "$MODEMSTATEFILE"
elif echo "$newstate" | grep "int32 3"; then
echo disabled > "$MODEMSTATEFILE"
else else
echo unknown > "$MODEMSTATEFILE" echo unknown > "$MODEMSTATEFILE"
fi fi
@ -302,6 +306,35 @@ mainloop() {
fi fi
done & done &
( #check whether the modem is still alive every minute, reset the modem if not
while :
do
sleep 60
TRIES=0
while [ "$TRIES" -lt 10 ]; do
MODEMS="$(mmcli -L)"
if echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null; then
break
elif grep -q rtc "$UNSUSPENDREASONFILE"; then
#don't bother checking in rtc-wake situations
TRIES=0
break
else
TRIES=$((TRIES+1))
echo "sxmo_modemmonitor: modem not found, waiting for modem... (try #$TRIES)">&2
sleep 2
if [ "$TRIES" -eq 10 ]; then
echo failed > "$MODEMSTATEFILE"
echo "sxmo_modemmonitor: forcing modem reset">&2
sxmo_modemmonitortoggle.sh reset #will kill the modemmonitor too
break
fi
fi
done
done
) &
wait
wait wait
wait wait
wait wait

@ -3,12 +3,30 @@
# This script toggles the modem monitor # This script toggles the modem monitor
# It optionally takes a parameter "on" or "off" # It optionally takes a parameter "on" or "off"
# forcing it to toggle only to that desired state if applicable. # forcing it to toggle only to that desired state if applicable.
# It may also take a "reset" parameter that forces the
# entire modem subsystem to reload
# include common definitions # include common definitions
# shellcheck source=scripts/core/sxmo_common.sh # shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh" . "$(dirname "$0")/sxmo_common.sh"
if [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then if [ "$1" = "reset" ]; then
#does a hard reset of the entire modem
echo "sxmo_modemmonitortoggle: forcing modem reset">&2
notify-send "Resetting modem, this may take a minute..."
pkill -TERM -f sxmo_modemmonitor.sh
sudo rc-service modemmanager stop
sudo rc-service eg25-manager stop
sleep 5
while ! rc-service eg25-manager status | grep -q started; do
sudo rc-service eg25-manager start
sleep 2
done
sleep 5
sudo rc-service modemmanager start
sleep 30
setsid -f sxmo_modemmonitor.sh &
elif [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then
pkill -TERM -f sxmo_modemmonitor.sh pkill -TERM -f sxmo_modemmonitor.sh
elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then
setsid -f sxmo_modemmonitor.sh & setsid -f sxmo_modemmonitor.sh &

Loading…
Cancel
Save