回答

收藏

树莓派使用4G模块上网

Raspberry Pi Raspberry Pi 5694 人阅读 | 0 人回复 | 2017-07-24


一、4G Luci配置
1、 新建一个wwan接口;
2、 上网方式为dhcp自动获取;
3、 物理设置选择wwan0;
4、 防火墙选择wan
二、重连脚本redial4g
  1. LogFile=/root/4g_Log.log
  2. mdate=`date +%R-%d-%m-%Y`

  3. if [ -e /var/run/udhcpc-wwan0.pid ]; then
  4.     echo 4G pid is ok!   
  5.     #echo $mdate 4G pid is ok! >> $LogFile
  6.     #exit 0
  7. else
  8.     echo 4G pid is failed!
  9.     echo $mdate 4G pid is failed! >> $LogFile
  10.     #/etc/myLte/dial4g
  11.     #reboot
  12.     #exit 0
  13. fi

  14. if ping -c3 www.baidu.com > /dev/null 2>&1
  15. then
  16.     echo ping baidu is ok!
  17.     #echo $mdate  ping baidu is ok! >> $LogFile
  18.     echo 0 > /tmp/4g_tmp.txt
  19.     exit 0
  20. else
  21.     echo ping baidu is failed!
  22.     echo $mdate ping baidu is failed! >> $LogFile
  23.     /etc/myLte/dial4g  #must place here
  24.     #read pvar < /tmp/4g_temp.txt
  25.     #if [ -z "$pvar" ] ; then
  26.     #    pvar=0
  27.     #fi   
  28.     if [ ! -f "/tmp/4g_tmp.txt" ] ; then
  29.         pvar=0
  30.         echo file not exist
  31.     else
  32.         read pvar < /tmp/4g_tmp.txt
  33.         echo file exist
  34.     fi
  35.     pvar=`expr $pvar + 1`
  36.     echo $pvar > /tmp/4g_tmp.txt
  37.     if [ $pvar -ge 5 ] ; then
  38.         echo failed 5 times!
  39.         echo $mdate failed 5 times! >> $LogFile
  40.         reboot   
  41.     fi
  42.      
  43. fi
  44. exit 0
复制代码
三、crontab
*/2 * * * * /etc/myLte/redial4g
重连时间不要设太短,太短可能还没拨号结束就又进行重播,会重复了。

四、拨号脚本dial4g
  1. PORT=/dev/ttyUSB0
  2. MODE="AT+CFUN=1" gcom -d $PORT -s /etc/gcom/setmode.gcom
  3. sleep 3
  4. MODE="AT+COPS=0" gcom -d $PORT -s /etc/gcom/setmode.gcom
  5. sleep 3
  6. MODE="AT+CEREG=1" gcom -d $PORT -s /etc/gcom/setmode.gcom
  7. sleep 3
  8. MODE="AT+CGDCONT=1,'IP'" gcom -d $PORT -s /etc/gcom/setmode.gcom
  9. sleep 3
  10. MODE="AT+CGACT=1,1" gcom -d $PORT -s /etc/gcom/setmode.gcom
  11. sleep 3
  12. MODE="AT+ZGACT=1,1" gcom -d $PORT -s /etc/gcom/setmode.gcom
  13. sleep 3
  14. ifup wwan &
  15. exit 0
复制代码
五、开机启动
  1. # Put your custom commands here that should be executed once
  2. # the system init finished. By default this file does nothing.

  3. /etc/myLte/dial4g

  4. exit 0
复制代码
转自互联网,作者念愧聚
关注下面的标签,发现更多相似文章
分享到:
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条