想了解一下樹莓派經過4G網絡模塊通訊如何實現,看到這篇文章(http://www.lxway.com/95811506.htm),準備接下來有機會實踐一下,先留存學習;網絡
1、4G Luci配置學習
一、 新建一個wwan接口;this
二、 上網方式爲dhcp自動獲取;htm
三、 物理設置選擇wwan0;blog
四、 防火牆選擇wan接口
2、重連腳本redial4gcrontab
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
3、crontabci
*/2 * * * * /etc/myLte/redial4g
重連時間不要設過短,過短可能還沒撥號結束就又進行重播,會重複了。get
4、撥號腳本dial4git
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
5、開機啓動
# 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