Hi3559AV100移植友方4G模块N720V5(二)

接上一篇文章《Hi3559AV100移植友方4G模块N720V5(一)》。

2.2 拨号脚本

4G模块拨号脚本一共分为3个,当然网上例程也有很多了,不过笔者在这里愿意再分享下这3个文件。

neoway-pppd-mobile

# Hide password in debug messages
hide-password

# The phone is not required to authenticate
noauth

# The chat script (be sure to edit that file,too!)
connect '/usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile'

# The close script(be sure to edit that file,too!)
disconnect '/usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-disconnect-mobile'

# Debug info from pppd
debug
# Modem path, like /dev/ttyUSB0, /dev/ttyACM0, depend on your module, default path is /dev/ttyUSB3
/dev/ttyACM2

# Serial port line speed
115200

# If you want to use the link as your gateway
defaultroute

# pppd must not propose any IP address to the peer
noipdefault

# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local

# For sanity, keep a lock on the serial line
lock
dump
# Keep pppd attached to the terminal
# Comment this to get daemon mode pppd
nodetach
# insert here the correct username and password for authentication
user "gsm"
password "1234"
# Hardware flow control
#crtscts
remotename 3gppp
ipparam 3gppp

# Ask the peer for up to 2 DNS server addresses
usepeerdns

neoway-chat-connect-mobile

TIMEOUT 5
ABORT "BUSY"
ABORT "DELAYED"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
#"AT
TIMEOUT 5
''AT
OK AT+CSQ
OK AT+CGDCONT=1,"IP","cmnet"
OK ATDT*99#
CONNECT ''

neoway-chat-disconnect-mobile

ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
""+++
""+++
""+++
SAY "\nGood bye!\n"

将这3个文件放在指定路径下,一般都是放在/etc/ppp/peers/下,笔者的环境特殊一些,放在了/usr/local/tools/etc/ppp/peers/下。当然,事先要创建好指定的存放路径。

之后进入上边的指定路径,在终端下运行以下命令:

/usr/local/tools/etc/ppp/peers # pppd file neoway-pppd-mobile

就可以映射出ppp0设备,并且上网了。log如下所示:

/usr/local/tools/etc/ppp/peers # pppd file neoway-pppd-mobile 
pppd options in effect:
debug           # (from neoway-pppd-mobile)
nodetach                # (from neoway-pppd-mobile)
dump            # (from neoway-pppd-mobile)
noauth          # (from neoway-pppd-mobile)
user gsm                # (from neoway-pppd-mobile)
password ??????         # (from neoway-pppd-mobile)
remotename 3gppp                # (from neoway-pppd-mobile)
/dev/ttyACM2            # (from neoway-pppd-mobile)
115200          # (from neoway-pppd-mobile)
lock            # (from neoway-pppd-mobile)
connect /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile            # (from neoway-pppd-mobile)
disconnect /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-disconnect-mobile              # (from neoway-pppd-mobile)
local           # (from neoway-pppd-mobile)
hide-password           # (from neoway-pppd-mobile)
novj            # (from neoway-pppd-mobile)
novjccomp               # (from neoway-pppd-mobile)
ipcp-accept-local               # (from neoway-pppd-mobile)
ipcp-accept-remote              # (from neoway-pppd-mobile)
ipparam 3gppp           # (from neoway-pppd-mobile)
noipdefault             # (from neoway-pppd-mobile)
defaultroute            # (from neoway-pppd-mobile)
usepeerdns              # (from neoway-pppd-mobile)
noccp           # (from neoway-pppd-mobile)
timeout set to 5 seconds
abort on (BUSY)
abort on (DELAYED)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 5 seconds
send (AT^M)
expect (OK)
^M
OK
 -- got it

send (AT+CSQ^M)
expect (OK)
^M
^M
+CSQ: 27,99^M
OK
 -- got it

send (AT+CGDCONT=1,"IP","cmnet"^M)
expect (OK)
^M
^M
OK
 -- got it

send (ATDT*99#^M)
expect (CONNECT)
^M
^M
CONNECT
 -- got it

send (^M)
Script /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile finished (pid 5138), status = 0x0
Serial connection established.
using channel 1
Using interface ppp0
Connect: ppp0 <--> /dev/ttyACM2
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfReq id=0x1 ]
sent [LCP ConfAck id=0x1 ]
rcvd [LCP ConfAck id=0x1 ]
sent [PAP AuthReq id=0x1 user="gsm" password=]
rcvd [PAP AuthAck id=0x1 "" 00]
PAP authentication succeeded
sent [IPCP ConfReq id=0x1 ]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfNak id=0x2 ]
rcvd [IPCP ConfNak id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfReq id=0x3]
sent [IPCP ConfAck id=0x3]
rcvd [IPCP ConfAck id=0x2 ]
Could not determine remote IP address: defaulting to 10.64.64.64
Failed to create /etc/ppp/resolv.conf: No such file or directory
not replacing existing default route via 10.58.122.1
local  IP address 10.25.19.67
remote IP address 10.64.64.64
primary   DNS address 221.179.155.193
secondary DNS address 221.179.155.209

 

这样,基于Hi3559AV100的友方4G模块移植圆满成功了!!!

 

但是,尚有以下几点需要注意:

1. neoway-pppd-mobile脚本中有几处需要视具体情况而改变,改为自己实际的(见下边红色字体):

1) 

# The chat script (be sure to edit that file,too!)
connect '/usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile'

2)

# The close script(be sure to edit that file,too!)
disconnect '/usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-disconnect-mobile'

3)

# Modem path, like /dev/ttyUSB0, /dev/ttyACM0, depend on your module, default path is /dev/ttyUSB3
/dev/ttyACM2

4)

# Serial port line speed
115200

2. 3个脚本在编辑时,格式要设置为Unix(LF)格式,千万不要设置成windows(CR LF)格式!!!否则会出现始终报错的问题,如下所示:

/usr/local/tools/etc/ppp/peers # pppd file neoway-pppd-mobile 
pppd options in effect:
debug           # (from neoway-pppd-mobile)
nodetach                # (from neoway-pppd-mobile)
dump            # (from neoway-pppd-mobile)
noauth          # (from neoway-pppd-mobile)
user gsm                # (from neoway-pppd-mobile)
password ??????         # (from neoway-pppd-mobile)
remotename 3gppp                # (from neoway-pppd-mobile)
/dev/ttyACM2            # (from neoway-pppd-mobile)
115200          # (from neoway-pppd-mobile)
lock            # (from neoway-pppd-mobile)
connect /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile            # (from neoway-pppd-mobile)
disconnect /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-disconnect-mobile              # (from neoway-pppd-mobile)
local           # (from neoway-pppd-mobile)
hide-password           # (from neoway-pppd-mobile)
novj            # (from neoway-pppd-mobile)
novjccomp               # (from neoway-pppd-mobile)
ipcp-accept-local               # (from neoway-pppd-mobile)
ipcp-accept-remote              # (from neoway-pppd-mobile)
ipparam 3gppp           # (from neoway-pppd-mobile)
noipdefault             # (from neoway-pppd-mobile)
defaultroute            # (from neoway-pppd-mobile)
usepeerdns              # (from neoway-pppd-mobile)
noccp           # (from neoway-pppd-mobile)
timeout set to 5 seconds
abort on (BUSY)
expect (^M)
alarm
Failed
Script /usr/local/tools/bin/chat -s -v -f /usr/local/tools/etc/ppp/peers/neoway-chat-connect-mobile finished (pid 8560), status = 0x3
Connect script failed

3. 拨号前要确保/etc/ppp/文件夹存在(如不存在需要手动创建),否则会报错,如下所示:

Could not determine remote IP address: defaulting to 10.64.64.64
Failed to create /etc/ppp/resolv.conf: No such file or directory
not replacing existing default route via 10.58.122.1

4. 拨号成功后,直接ping www.baidu.com 查看实际是否能够上网。如果ping不通,需要修改设置,终端输入:route add default ppp0,默认设置路由出去的不一定是 ppp0。

5. 如果可以ping通百度的ip,但不能ping通www,baidu.com,需要执行以下命令:

cp –f /etc/ppp/resolv.conf /etc/resolv.com

6. 如果pppd file neoway-pppd-mobile后边不加&,则Ctrl+C时调用chat-disconnect脚本;如果带上&,即后台运行,则当kill运行此命令的进程时,chat-disconnect脚本调用。

 

你可能感兴趣的:(Hi35XX,Linux,c\c++)