一、目的 4G模组拨号成功后,发现还是不能正常连接外网。 这时还需要通过dhcp来获取ip,同时需要修改/etc/resolv.conf配置域名后才能正常上网;另外我们还担心网络是否会出现异常,此时需要守护网
4G模组拨号成功后,发现还是不能正常连接外网。
这时还需要通过dhcp来获取ip,同时需要修改/etc/resolv.conf配置域名后才能正常上网;另外我们还担心网络是否会出现异常,此时需要守护网络的健康,让网络实时在线。
这里记录调试过程,并提供编写的可用脚本和配置文件。
主要包含:
1.移植L610到openwrt下,通过4G CAT1实现ECM拨号上网
这步骤这里不重复介绍
2.openwrt开发板 MT7628D
Barrier Breaker 版本号是14.07,linux内核版本3.10.14
3.编译host主机:ubuntu 14.04.5 LTS
4.L610和 MT726D通过USB连接
进入主目录
# make menuconfig# make V=99
编译后的输出目录在builddir目录下
其中固件在bin/ramips/
因为配置需要用到几个工具,需要配置起来,可以参考如下来设置
# make menuconfig
后找到microcom勾选,microcom是一个串口工具,是用于和4G模组的AT命令测试的。非必选,调试用。
同样方法找打comgt工具编译,comgt工具可以用来配置拨号脚本
配置好后,保存
# make V=99
系统中要配置到这里完成,重新烧录系统即可。
整体流程如下:
配置模组模式为ECM,详见dialog-ecm.gcom文件
opengt set com 115200n81 set comecho off set senddelay 0.02 waitquiet 0.2 0.2 flash 0.1:start send "AT+GTUSBMODE=74^m" waitfor 30 "OK","ERROR" if % = -1 Goto error if % = 0 goto ready if % = 1 goto error:error print $s," ***setusbmode ERROR***" exit 1:ready print "setusbmode OK\n" exit 0
配置模组自动拨号,详见dialog.gcom文件
opengt set com 115200n81 set comecho off set senddelay 0.02 waitquiet 0.2 0.2 flash 0.1:start send "AT+CPIN?^m" waitfor 30 "SIM PUK","SIM PIN","READY","ERROR","ERR" if % = -1 goto error if % = 0 goto ready if % = 1 goto error if % = 2 goto ready if % = 3 goto error if % = 4 goto error:error print $s," ***SIM ERROR***" print "Check device port configuration.\nCheck SIM is inserted\nTest SIM in a mobile phone?\n" exit 1:ready print "SIM ready\n":waitreg send "AT+CGREG?^m" waitfor 2 print $s:signal send "AT+CSQ?^m" get 2 "^m" $s get 2 "^m" $s let a=len($s) let a=a-6 let $s=$right($s,a) if $s <> "0,0" goto sigcont if c > 3 goto sigexit let c=c+1 pause 1 goto signal:sigexit print "Signal strength measure 0,0 too low!" exit 1:sigcont print "Signal Quality:",$s,"\n":SetGTRNDIS send "AT+GTRNDIS=1,1^m" waitfor 3 "OK","ERROR" print $s:GetGTRNDIS send "AT+GTRNDIS?^m" get 2 "^m" $s print $s get 2 "^m" $s print $s:OK print "Set LTE module OK\n" exit 0
这里把拨号获取dhcp以及配置dns写到一个脚本中
详见watch_network.sh文件
#!/bin/sh#sleep 100DATE=`date +%Y-%m-%d-%H:%M:%S`tries=0HOST_URL="aliyuncs.com"USB_MODE_CMD="comgt -d /dev/ttyUSB0 -s /root/arm-target/dialog-ecm.gcom"DIALOG_CMD="comgt -d /dev/ttyUSB0 -s /root/arm-target/dialog.gcom"KILL_UDHCPC_CMD="ps | grep udhcpc | grep -v grep | awk '{print $1}'|xargs kill -9"LOG_FILE="/tmp/watch_network.log"echo $DATE --- watch network start --- >> $LOG_FILEwhile [[ $tries -lt 3 ]]do if /bin/ping -c 1 $HOST_URL >/dev/null then echo $DATE --- exit --- >> $LOG_FILE echo $DATE OK >> $LOG_FILE exit 0 fi tries=$((tries+1)) sleep 5# echo $DATE tries: $tries >>watch_network.logdone echo $DATE network restart >> $LOG_FILE# rerst LTEgpio setdir 37 1gpio write 37 1sleep 1gpio write 37 0sleep 5# set ecmmode$USB_MODE_CMD# rerst LTE againgpio setdir 37 1gpio write 37 1sleep 1gpio write 37 0sleep 5# call comgt dialog$DIALOG_CMDsleep 3# udhcpc# kill udhcpc tiwce$KILL_UDHCPC_CMD$KILL_UDHCPC_CMDecho $DATE start dhcpc >> $LOG_FILEudhcpc -i eth1 -s /usr/share/udhcpc/default-dns.script#/etc/init.d/network restart#echo $DATE reboot >>watch_network.log#reboot1
上传default-dns.script文件到板子的目录:/usr/share/udhcpc/default-dns.script,并给权限
# chmod 775 /usr/share/udhcpc/default-dns.script
#!/bin/sh# udhcpc script edited by Tim Riker RESOLV_CONF="/etc/resolv.conf" [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; } NETMASK=""[ -n "$subnet" ] && NETMASK="netmask $subnet"BROADCAST="broadcast +"[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" case "$1" in deconfig) echo "Setting IP address 0.0.0.0 on $interface" busybox ifconfig $interface 0.0.0.0 ;; renew|bound) echo "Setting IP address $ip on $interface" busybox ifconfig $interface $ip $NETMASK $BROADCAST if [ -n "$router" ] ; then echo "Deleting routers" while busybox route del default gw 0.0.0.0 dev $interface ; do : done metric=0 for i in $router ; do echo "Adding router $i" busybox route add default gw $i dev $interface metric $metric : $(( metric += 1 )) done fi echo "Recreating $RESOLV_CONF" # If the file is a symlink somewhere (like /etc/resolv.conf # pointing to /run/resolv.conf), make sure things work. realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF") tmpfile="$realconf-$$" > "$tmpfile" [ -n "$domain" ] && echo "search $domain" >> "$tmpfile" for i in $dns ; do echo " Adding DNS server $i" echo "nameserver $i" >> "$tmpfile" done busybox mv "$tmpfile" "$realconf" ;;esac exit 0
在cron中增加网络监控守护脚本,每5分钟执行一次:
# crontab -e
输入内容:
*/5 * * * * /root/arm-target/watch_network.sh
按ESC后,按: 输入qw
查看任务
# crontab -l
开机自动拨号可以在上电初次的时候,增加拨号速度,而不用每次等待网络监控守护脚本的执行周期
上传文件到板子:/etc/init.d/startAutoDialog
给权限
# chmod 775 /etc/init.d/startAutoDialog
#!/bin/sh # /etc/init.d/startAutoDialogSTART=95start(){/root/run_dialog.sh &}stop(){}
创建链接
# ln -s /etc/init.d/startAutoDialog /etc/rc.d/S95startAutoDialog
#!/bin/sh # /root/run_dialog.shPROJECT_DIR="/root/"DATE=`date +%Y-%m-%d-%H:%M:%S`echo $DATE run dialog > $PROJECT_DIR/auto_dialog.log# start LTEcd $PROJECT_DIR/./watch_network.sh &
以上配置完成后,检查sim卡,天线硬件连接OK后,重启板子。
ping 测试网络
# ping www.baidu.com
来源地址:https://blog.csdn.net/fzhenyu/article/details/126408605
--结束END--
本文标题: openwrt移植4G CAT1 (L610) ——自动拨号,获取DNS,守护网络实时在线
本文链接: https://lsjlt.com/news/384354.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0