EC20模块串口交互存在问题

您好,我这里有一块ec20模块,在通过核心板引出的原生串口进行交互的过程中经常存在一些问题,拨号成功时的打印如下所示,可以正常的获取到ip,并且设置好路由之后可以正常通外网。

dgri:~/test/test$ sudo ./quectel-pppd.sh 
quectel-pppd options in effect:
devname   /dev/ttyS6    # (default)
apn       3gnet    # (default)
user      user   # (default)
password  passwd   # (default)
pppd options in effect:
debug		# (from command line)
nodetach		# (from command line)
dump		# (from command line)
noauth		# (from command line)
user user		# (from command line)
password ??????		# (from command line)
/dev/ttyS6		# (from command line)
9600		# (from command line)
lock		# (from command line)
connect ''chat -s -v ABORT BUSY ABORT \"NO CARRIER\" ABORT \"NO DIALTONE\" ABORT ERROR ABORT \"NO ANSWER\" TIMEOUT 30 \"\" AT OK ATE0 OK ATI\\;+CSUB\\;+CSQ\\;+CPIN?\\;+COPS?\\;+CGREG?\\;\\&D2 OK AT+CGDCONT=1,\\\"IP\\\",\\\"3gnet\\\",,0,0 OK ATD*99# CONNEC
		# (from command line)
disconnect chat -s -v ABORT ERROR ABORT \"NO DIALTONE\" SAY \"\\nSending break to the modem\\n\" \"\" +++ \"\" +++ \"\" +++ SAY \"\\nGood bay\\n\"		# (from command line)
nocrtscts		# (from command line)
modem		# (from command line)
novj		# (from command line)
novjccomp		# (from command line)
ipcp-accept-local		# (from command line)
ipcp-accept-remote		# (from command line)
noipdefault		# (from command line)
ipcp-max-configure 30		# (from command line)
defaultroute		# (from command line)
usepeerdns		# (from command line)
noccp		# (from command line)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 30 seconds
send (AT^M)
expect (OK)
^M
OK
 -- got it

send (ATE0^M)
expect (OK)
^M
^M
OK
 -- got it

send (ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2^M)
expect (OK)
^M
^M
Quectel^M
EC20F^M
Revision: EC20CEHBR06A08M1G_GW^M
SubEdition: V06^M
+CSQ: 31,99^M
+CPIN: READY^M
+COPS: 0,0,"CHINA MOBILE",7^M
+CGREG: 0,1^M
OK
 -- got it

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

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

Script ''chat -s -v ABORT BUSY ABORT "NO CARRIER" ABORT "NO DIALTONE" ABORT ERROR ABORT "NO ANSWER" TIMEOUT 30 "" AT OK ATE0 OK ATI\;+CSUB\;+CSQ\;+CPIN?\;+COPS?\;+CGREG?\;\&D2 OK AT+CGDCONT=1,\"IP\",\"3gnet\",,0,0 OK ATD*99# CONNECT'' finished (pid 1014), status = 0x0
Serial connection established.
using channel 2
Using interface ppp0
Connect: ppp0 <--> /dev/ttyS6
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x217773eb> <pcomp> <accomp>]
rcvd [LCP ConfReq id=0x2 <asyncmap 0x0> <auth chap MD5> <magic 0xc938160f> <pcomp> <accomp>]
sent [LCP ConfAck id=0x2 <asyncmap 0x0> <auth chap MD5> <magic 0xc938160f> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x217773eb> <pcomp> <accomp>]
rcvd [LCP DiscReq id=0x3 magic=0xc938160f]
rcvd [CHAP Challenge id=0x1 <63f6361c99b4104949bb087a8d15df9a>, name = "UMTS_CHAP_SRVR"]
sent [CHAP Response id=0x1 <b7ca44707c7f3a449f1325f2d317b3ea>, name = "user"]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
kernel does not support PPP filtering
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
sent [IPV6CP ConfReq id=0x1 <addr fe80::34e9:887d:5694:dd82>]
rcvd [IPCP ConfReq id=0x2]
sent [IPCP ConfNak id=0x2 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1 <addr 10.222.141.184> <ms-dns1 111.32.26.49> <ms-dns2 111.32.0.177>]
sent [IPCP ConfReq id=0x2 <addr 10.222.141.184> <ms-dns1 111.32.26.49> <ms-dns2 111.32.0.177>]
rcvd [IPCP ConfReq id=0x3]
sent [IPCP ConfAck id=0x3]
rcvd [IPCP ConfAck id=0x2 <addr 10.222.141.184> <ms-dns1 111.32.26.49> <ms-dns2 111.32.0.177>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing default route to enps0 [10.15.1.1]
local  IP address 10.222.141.184
remote IP address 10.64.64.64
primary   DNS address 111.32.26.49
secondary DNS address 111.32.0.177
Script /etc/ppp/ip-up started (pid 1018)
Script /etc/ppp/ip-up finished (pid 1018), status = 0x0
sent [IPV6CP ConfReq id=0x1 <addr fe80::34e9:887d:5694:dd82>]
sent [IPV6CP ConfReq id=0x1 <addr fe80::34e9:887d:5694:dd82>]

模块正常时,当发送ATI查看模块信息时可以获取到如下的信息

Quectel
EC20F
Revision: EC20CEHBR06A08M1G_GW
OK

但是往往模块无法正常的进行交互,通常情况下模块重新上电之后(通过电源指示灯以及网络灯观测),直接使用拨号脚本进行拨号,获取到的打印信息如下所示,由于模块回复超时,往往我在测试的过程中会重新使用拨号脚本进行测试,但是后续与模块的交互无法获得回应,即使是简单的AT也无法收到OK的回复。

dgri:~/test/test$ sudo ./quectel-pppd.sh 
quectel-pppd options in effect:
devname   /dev/ttyS6    # (default)
apn       3gnet    # (default)
user      user   # (default)
password  passwd   # (default)
pppd options in effect:
debug		# (from command line)
nodetach		# (from command line)
dump		# (from command line)
noauth		# (from command line)
user user		# (from command line)
password ??????		# (from command line)
/dev/ttyS6		# (from command line)
9600		# (from command line)
lock		# (from command line)
connect ''chat -s -v ABORT BUSY ABORT \"NO CARRIER\" ABORT \"NO DIALTONE\" ABORT ERROR ABORT \"NO ANSWER\" TIMEOUT 30 \"\" AT OK ATE0 OK ATI\\;+CSUB\\;+CSQ\\;+CPIN?\\;+COPS?\\;+CGREG?\\;\\&D2 OK AT+CGDCONT=1,\\\"IP\\\",\\\"3gnet\\\",,0,0 OK ATD*99# CONNEC
		# (from command line)
disconnect chat -s -v ABORT ERROR ABORT \"NO DIALTONE\" SAY \"\\nSending break to the modem\\n\" \"\" +++ \"\" +++ \"\" +++ SAY \"\\nGood bay\\n\"		# (from command line)
nocrtscts		# (from command line)
modem		# (from command line)
novj		# (from command line)
novjccomp		# (from command line)
ipcp-accept-local		# (from command line)
ipcp-accept-remote		# (from command line)
noipdefault		# (from command line)
ipcp-max-configure 30		# (from command line)
defaultroute		# (from command line)
usepeerdns		# (from command line)
noccp		# (from command line)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 30 seconds
send (AT^M)
expect (OK)
^M
OK
 -- got it

send (ATE0^M)
expect (OK)
^M
^M
OK
 -- got it

send (ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2^M)
expect (OK)
^M
alarm
Failed
Script ''chat -s -v ABORT BUSY ABORT "NO CARRIER" ABORT "NO DIALTONE" ABORT ERROR ABORT "NO ANSWER" TIMEOUT 30 "" AT OK ATE0 OK ATI\;+CSUB\;+CSQ\;+CPIN?\;+COPS?\;+CGREG?\;\&D2 OK AT+CGDCONT=1,\"IP\",\"3gnet\",,0,0 OK ATD*99# CONNECT'' finished (pid 1081), status = 0x3
Connect script failed

模块不正常的状态下,使用串口助手与模块进行交互,会发现与正常时完全相同的串口助手设置,仅仅按下键盘的第一个键就会收到ok的回复,而且无论按下哪个键都会收到这样的回复,按下第二个键时收到的就是乱码了,再之后无论选择脚本进行交互还是使用串口助手都无法收到模块的回复,详细的打印信息如下。

dgri:~/test/test$ sudo ./picocom /dev/ttyS6
picocom v3.2a

port is        : /dev/ttyS6
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready

OK
怘þ怘

在上面所有的测试过程中使用的串口通讯的波特率等设置是完全相同的。目前我遇到的问题是,在非常多次的测试过程中,往往模块是不正常的状态,仅有很少次是正常的,可以拨号成功的,请问我应该尝试从哪些方面解决这个问题呢

我看你发pppd 日志,是没有注网,不是AT不通。默认使用的波特率是115200,不是9600.

我现在对于模块比较疑惑的是它偶尔可以正常拨号,即使是在表现不太正常的时候我与它进行交互,它在第一次交互时也会回复我,即使回复的结果不一定正确(这里是测试的时候我给它发送什么发现都会回复给我ok),之后的交互就完全没有反应了,只有进行断电重启之后才能重新进行交互,但是也不一定是正常的状态,是否有某些设置或者调试过程中某些点需要注意呢

感谢您的回复,在模块工作不正常的情况下,第一次拨号失败之后我重新进行拨号,在第一个at指令发出之后就会超时,甚至我使用串口工具进行交互也无法得到回复

dgri:~/test/test$ sudo ./quectel-pppd.sh 
quectel-pppd options in effect:
devname   /dev/ttyS6    # (default)
apn       3gnet    # (default)
user      user   # (default)
password  passwd   # (default)
pppd options in effect:
debug		# (from command line)
nodetach		# (from command line)
dump		# (from command line)
noauth		# (from command line)
user user		# (from command line)
password ??????		# (from command line)
/dev/ttyS6		# (from command line)
115200		# (from command line)
lock		# (from command line)
connect ''chat -s -v ABORT BUSY ABORT \"NO CARRIER\" ABORT \"NO DIALTONE\" ABORT ERROR ABORT \"NO ANSWER\" TIMEOUT 30 \"\" AT OK ATE0 OK ATI\\;+CSUB\\;+CSQ\\;+CPIN?\\;+COPS?\\;+CGREG?\\;\\&D2 OK AT+CGDCONT=1,\\\"IP\\\",\\\"3gnet\\\",,0,0 OK ATD*99# CONNEC
		# (from command line)
disconnect chat -s -v ABORT ERROR ABORT \"NO DIALTONE\" SAY \"\\nSending break to the modem\\n\" \"\" +++ \"\" +++ \"\" +++ SAY \"\\nGood bay\\n\"		# (from command line)
nocrtscts		# (from command line)
modem		# (from command line)
novj		# (from command line)
novjccomp		# (from command line)
ipcp-accept-local		# (from command line)
ipcp-accept-remote		# (from command line)
noipdefault		# (from command line)
ipcp-max-configure 30		# (from command line)
defaultroute		# (from command line)
usepeerdns		# (from command line)
noccp		# (from command line)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 30 seconds
send (AT^M)
expect (OK)
^M
OK
 -- got it

send (ATE0^M)
expect (OK)
^M
^M
OK
 -- got it

send (ATI;+CSUB;+CSQ;+CPIN?;+COPS?;+CGREG?;&D2^M)
expect (OK)
^M
alarm
Failed
Script ''chat -s -v ABORT BUSY ABORT "NO CARRIER" ABORT "NO DIALTONE" ABORT ERROR ABORT "NO ANSWER" TIMEOUT 30 "" AT OK ATE0 OK ATI\;+CSUB\;+CSQ\;+CPIN?\;+COPS?\;+CGREG?\;\&D2 OK AT+CGDCONT=1,\"IP\",\"3gnet\",,0,0 OK ATD*99# CONNECT'' finished (pid 747), status = 0x3
Connect script failed
dgri:~/test/test$ sudo ./quectel-pppd.sh 
quectel-pppd options in effect:
devname   /dev/ttyS6    # (default)
apn       3gnet    # (default)
user      user   # (default)
password  passwd   # (default)
pppd options in effect:
debug		# (from command line)
nodetach		# (from command line)
dump		# (from command line)
noauth		# (from command line)
user user		# (from command line)
password ??????		# (from command line)
/dev/ttyS6		# (from command line)
115200		# (from command line)
lock		# (from command line)
connect ''chat -s -v ABORT BUSY ABORT \"NO CARRIER\" ABORT \"NO DIALTONE\" ABORT ERROR ABORT \"NO ANSWER\" TIMEOUT 30 \"\" AT OK ATE0 OK ATI\\;+CSUB\\;+CSQ\\;+CPIN?\\;+COPS?\\;+CGREG?\\;\\&D2 OK AT+CGDCONT=1,\\\"IP\\\",\\\"3gnet\\\",,0,0 OK ATD*99# CONNEC
		# (from command line)
disconnect chat -s -v ABORT ERROR ABORT \"NO DIALTONE\" SAY \"\\nSending break to the modem\\n\" \"\" +++ \"\" +++ \"\" +++ SAY \"\\nGood bay\\n\"		# (from command line)
nocrtscts		# (from command line)
modem		# (from command line)
novj		# (from command line)
novjccomp		# (from command line)
ipcp-accept-local		# (from command line)
ipcp-accept-remote		# (from command line)
noipdefault		# (from command line)
ipcp-max-configure 30		# (from command line)
defaultroute		# (from command line)
usepeerdns		# (from command line)
noccp		# (from command line)
abort on (BUSY)
abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
timeout set to 30 seconds
send (AT^M)
expect (OK)
alarm
Failed
Script ''chat -s -v ABORT BUSY ABORT "NO CARRIER" ABORT "NO DIALTONE" ABORT ERROR ABORT "NO ANSWER" TIMEOUT 30 "" AT OK ATE0 OK ATI\;+CSUB\;+CSQ\;+CPIN?\;+COPS?\;+CGREG?\;\&D2 OK AT+CGDCONT=1,\"IP\",\"3gnet\",,0,0 OK ATD*99# CONNECT'' finished (pid 751), status = 0x3
Connect script failed

以及第一次拨号失败之后使用串口工具进行交互的结果

dgri:~/test/test$ sudo ./picocom -c /dev/ttyS6 -b 115200 
picocom v3.2a

port is        : /dev/ttyS6
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : yes
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready
at
at
at
at
at
at

我猜测,你应该是直接kill -9 停掉了pppd。然后这个AT串口其实还是在透传模式,所以看到的现象就是AT不通了。

非常感谢您的回复,您提供的思路确实是之前没有考虑到的点,但是实际测试过程中退出的时候确实是Ctrl + c 中断的拨号脚本,尝试通过串口发送 +++ 切换模式也没有成功,但是最终问题也得到了解决,重新购买了新的成品4G模块,验证问题为之前的4G模块损坏导致,新的EC20模块没有问题,抱歉耽误了您的时间,非常感谢您的帮助

ctrl +C 发的就是kill. 这样pppd 走不到 pppd diconnect 直接断开了。一般是建议发terminate 信号,即kill -15.
如果真的发了SIG KILL,大多数情况,再发 +++ 是能退出透传的。但是对发+++ 也是有要求的,请看相应的指导手册。