#!/bin/bash
string='Gobi'
info_eth1=$(ethtool -i eth1 | grep 'driver')
if [[ $info_eth1 == *$string* ]]
then
echo 'eth1 as 4g eth node'
eth_no='eth1'
else
echo 'eth0 as 4g eth node'
eth_no='eth0'
fi
#echo -e "AT+CGATT?\r\n" > /dev/ttyUSB2;
#res1=$(head -n3 /dev/ttyUSB2 | grep "CGATT: 1")
#echo $res1
echo 'Power up 4G module and dial, please wait'
#--- turn off radio and SIM power
echo -e "AT+CFUN=0,1\r\n" > /dev/ttyUSB2
sleep 5
for i in {1..20}
do
if [ -c /dev/ttyUSB2 ];then
#AT 指令参考 Neoway_N720_AT命令手册
cat /dev/ttyUSB2 &
echo -e "ATI\r\n" > /dev/ttyUSB2
sleep 1
echo -e "ATI+CCID\r\n" > /dev/ttyUSB2
sleep 1
echo -e "ATI+CREG?\r\n" > /dev/ttyUSB2
sleep 1
echo -e "ATI+CSQ\r\n" > /dev/ttyUSB2
sleep 5
#运行拨号,如返回$QCRMCALL: 1 V4则正常
echo -e "AT\$QCRMCALL=1,1\r\n" > /dev/ttyUSB2
sleep 1
echo -e "AT\$QCRMCALL=1,1\r\n" > /dev/ttyUSB2
sleep 5
udhcpc -i $eth_no
sleep 1
ipaddr=$(/sbin/ifconfig $eth_no|grep inet|grep -v 127.0.0.1|grep -v inet6 | awk '{print $2}' | tr -d "addr:")
for j in {1..5} #check ip get or not
do
if [ -z "$ipaddr" ]; then
echo 'can not get ip re-dhcp'
udhcpc -i $eth_no
sleep 1
else
echo $ipaddr
exit
fi
done
exit
else
echo '4G Module reset, just waiting '
sleep 1
fi
done
#PS: 其他AT 指令参考
#断开拨号
#echo -e "AT\$QCRMCALL=0,1\r\n" > /dev/ttyUSB2
#sleep 3
#如下为关闭模块和飞行模式操作方法,供参考
#--- turn off radio and fly mode
#echo -e "AT+CFUN=4,0\r\n" > /dev/ttyUSB2
#sleep 1
#--- turn off radio and SIM power
#echo -e "AT+CFUN=0,0\r\n" > /dev/ttyUSB2
#sleep 1
#--- turn on radio and full function (default)
#echo -e "AT+CFUN=1\r\n" > /dev/ttyUSB2
#sleep 10
#--- Check CFUN state
#echo -e "AT+CFUN?\r\n" > /dev/ttyUSB2
以上脚本适用于T600/T100/T101/T200等型号,但需root 执行
参考文档:
Neoway_N720_AT命令手册(标准版)
Neoway_N720_Linux集成用户手册
网友评论