【树莓派】树莓派使用4G模块上网

简介:

一、4G Luci配置

1、 新建一个wwan接口;

2、 上网方式为dhcp自动获取;

3、 物理设置选择wwan0;

4、 防火墙选择wan

二、重连脚本redial4g

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
LogFile=/root/4g_Log.log
mdate=`date +%R-%d-%m-%Y`
 
if  [ -e / var /run/udhcpc-wwan0.pid ]; then
     echo 4G pid  is  ok!   
     #echo $mdate 4G pid is ok! >> $LogFile
     #exit 0
else
     echo 4G pid  is  failed!
     echo $mdate 4G pid  is  failed! >> $LogFile
     #/etc/myLte/dial4g
     #reboot
     #exit 0
fi
 
if  ping -c3 www.baidu.com > /dev/ null  2>&1
then
     echo ping baidu  is  ok!
     #echo $mdate  ping baidu is ok! >> $LogFile
     echo 0 > /tmp/4g_tmp.txt
     exit 0
else
     echo ping baidu  is  failed!
     echo $mdate ping baidu  is  failed! >> $LogFile
     /etc/myLte/dial4g  #must place here
     #read pvar < /tmp/4g_temp.txt
     #if [ -z "$pvar" ] ; then
     #    pvar=0
     #fi   
     if  [ ! -f  "/tmp/4g_tmp.txt"  ] ; then
         pvar=0
         echo file not exist
     else
         read pvar < /tmp/4g_tmp.txt
         echo file exist
     fi
     pvar=`expr $pvar + 1`
     echo $pvar > /tmp/4g_tmp.txt
     if  [ $pvar -ge 5 ] ; then
         echo failed 5 times!
         echo $mdate failed 5 times! >> $LogFile
         reboot   
     fi
     
fi
exit 0

  

三、crontab

*/2 * * * * /etc/myLte/redial4g

重连时间不要设太短,太短可能还没拨号结束就又进行重播,会重复了。

四、拨号脚本dial4g

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PORT=/dev/ttyUSB0
MODE= "AT+CFUN=1"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
MODE= "AT+COPS=0"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
MODE= "AT+CEREG=1"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
MODE= "AT+CGDCONT=1,'IP'"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
MODE= "AT+CGACT=1,1"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
MODE= "AT+ZGACT=1,1"  gcom -d $PORT -s /etc/gcom/setmode.gcom
sleep 3
ifup wwan &
exit 0

  

五、开机启动

1
2
3
4
5
6
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
 
/etc/myLte/dial4g
 
exit 0

  

 
相关文章
|
8月前
|
Java Linux 芯片
树莓派基础
简写RPI,只有信用卡大小的微型电脑,系统基于Linux。自树莓派问世以来,受众多计算机发烧友和创客的追捧,曾经一“派”难求。别看其外表“娇小”
|
编解码 文件存储 异构计算
初识树莓派
初识树莓派
111 0
初识树莓派
|
网络安全 数据安全/隐私保护 Windows
树莓派系列-3-连接到树莓派
树莓派系列-3-连接到树莓派
158 0
|
安全
树莓派系列-1-初识树莓派,把它装起来
树莓派系列-1-初识树莓派,把它装起来
118 0
树莓派系列-1-初识树莓派,把它装起来
用树莓派做笔记本电脑
树莓派官方杂志MagPi 第74期翻译 翻译:子豪兄(同济大学) 加入翻译组或相关合作请关注微信公众号MagPi ,私聊后台 欢迎各论坛网站公众号分享转载,请以 原文超链接或链接形式 转载并注明出处 子豪兄。
2547 0