Linux UMTS Script


Um mir die UMTS Einwahl zu erleichtern, hab ich mir dafür ein Script geschrieben.

Das Script läuft bei mir zuverlässig, ohne dass ich mehr machen müsste als das Script starten.

#!/bin/bash
# Die Pin für die SIM-Karte
PIN=1234

CONTROL_DEVICE=/dev/ttyACM0
UMTS_DEVICE=/dev/ttyACM1
GPS_DEVICE=/dev/ttyACM2

chmod 777 $CONTROL_DEVICE
chmod 777 $UMTS_DEVICE 
chmod 777 $GPS_DEVICE

startumts()
{
	/etc/init.d/NetworkManager stop
	echo -n " * Checking PIN ... "
	/usr/sbin/chat -t 1 -v "" "AT+CPIN?" "READY" > $CONTROL_DEVICE < $CONTROL_DEVICE
	STATUS_PIN=$?
	echo -n "$STATUS_PIN "
	if [ $STATUS_PIN -gt 0 ] ; then
		echo "MISSING";
		echo -n " * Sending PIN ... "
		/usr/sbin/chat -t 1 -v "" "AT+CPIN=\"$PIN\"" "OK" > $CONTROL_DEVICE < $CONTROL_DEVICE
		SET_PIN=$?
		echo -n "$SET_PIN "
		if [ $SET_PIN -gt 0 ] ; then
			echo "ERROR"
			exit;
		else 
			echo "OK";
		fi
	else
		echo "OK";
	fi
	echo -n " * Checking Antenna ... "
	/usr/sbin/chat -t 2 -v "" "AT+CFUN=1" "OK" > $CONTROL_DEVICE < $CONTROL_DEVICE
	STATUS_ANTENNA=$?
	echo -n "$STATUS_ANTENNA "
	if [ $STATUS_ANTENNA -gt 0 ] ; then
		echo "ERROR"
		exit
	else 
		echo "OK"
	fi
	echo -n " * Starting UMTS ... "
	sleepx 5
	while [ 1 ] ; do
		wvdial
	done
}
poweroff()
{
	echo " * Funk-Modul deaktivieren ...";
	/usr/sbin/chat -t 2 -v "" "AT+CFUN=4" "OK" > $CONTROL_DEVICE < $CONTROL_DEVICE
}
sleepx()
{
	T=$1
	while [ $T -gt 0 ] ; do
		echo -n "."
		T=$(( $T - 1 ))
		sleep 1
	done
	echo ""
}
resetdev()
{
	echo " * Funk-Modul reset ...";
	/usr/sbin/chat -t 2 -v "" "AT*E2RESET" "OK" > $CONTROL_DEVICE < $CONTROL_DEVICE
	sleepx 20
}
case "$1" in
  start)
	startumts
	;;
  stop)
	echo "Stopping UMTS"
	poweroff
	;;
  reset)
	echo "RESET DEVICE"
	resetdev
	;;
  *)
	echo "$0 start or $0 stop"
	;;
esac

Created: 2009-10-14
Tags: linux umts
Words: 283