ModemMonitor: Periodically check whether the modem is still alive, reset it if not
Signed-off-by: Stacy Harper <contact@stacyharper.net>
This commit is contained in:
		
							parent
							
								
									13b29f7139
								
							
						
					
					
						commit
						edc48a01d2
					
				
					 5 changed files with 59 additions and 1 deletions
				
			
		
							
								
								
									
										4
									
								
								configs/sudo/modem
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								configs/sudo/modem
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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_ard Brightness               ^ 1 ^ sxmo_brightness.sh down
 | 
			
		||||
			$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_phl Modem Log                  ^ 0 ^ sxmo_modemlog.sh
 | 
			
		||||
			$icon_wif Wifi $(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,6 +48,8 @@ update() {
 | 
			
		|||
			MODEMMON=""
 | 
			
		||||
		elif [ connected = "$MODEMSTATE" ]; then
 | 
			
		||||
			MODEMMON=""
 | 
			
		||||
		elif [ failed = "$MODEMSTATE" ] || [ disconnected = "$MODEMSTATE" ]; then
 | 
			
		||||
			MODEMMON=""
 | 
			
		||||
		else
 | 
			
		||||
			MODEMMON=""
 | 
			
		||||
		fi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -295,6 +295,10 @@ mainloop() {
 | 
			
		|||
				elif echo "$newstate" | grep "int32 11"; then
 | 
			
		||||
					echo connected > "$MODEMSTATEFILE"
 | 
			
		||||
					#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
 | 
			
		||||
					echo unknown > "$MODEMSTATEFILE"
 | 
			
		||||
				fi
 | 
			
		||||
| 
						 | 
				
			
			@ -302,6 +306,35 @@ mainloop() {
 | 
			
		|||
			fi
 | 
			
		||||
		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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,12 +3,30 @@
 | 
			
		|||
# This script toggles the modem monitor
 | 
			
		||||
# It optionally takes a parameter "on" or "off"
 | 
			
		||||
# 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
 | 
			
		||||
# shellcheck source=scripts/core/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
 | 
			
		||||
elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then
 | 
			
		||||
	setsid -f sxmo_modemmonitor.sh &
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue