zoukankan      html  css  js  c++  java
  • 【树莓派】树莓派使用4G模块上网

    想了解一下树莓派通过4G网络模块通信如何实现,看到这篇文章(http://www.lxway.com/95811506.htm),准备接下来有机会实践一下,先留存学习;

    一、4G Luci配置

    1、 新建一个wwan接口;

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

    3、 物理设置选择wwan0;

    4、 防火墙选择wan

    二、重连脚本redial4g

    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

    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
    

      

    五、开机启动

    # 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
    

      




  • 相关阅读:
    程序员的人品
    【转】telnet使用 删除foxmail不能收取的邮件
    35岁以后我在干什么?
    面试
    程序员基本知识数制
    一事无成
    经过XssFilter替换特殊字符后再经zuul路由转发httpEntity缺少内容
    android跳转到市场进行评价 market://search?q
    使用IntelliJ 12.1.12开发android程序
    重定向
  • 原文地址:https://www.cnblogs.com/haochuang/p/6215022.html
Copyright © 2011-2022 走看看