4G模块连接开发板
插入sim卡和4g后网卡上电开发板,如果没有下图中 ttyUSB0~ttyUSB3则需要按后续方法使能4g模块引脚。
使能4G模块引脚
对于100ask imx6ull pro开发板 需要先执行如下操作来使能4G模块使能引脚(默认系统会进行初始化操作)。
echo 133 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio133/direction
echo 1 > /sys/class/gpio/gpio133/value
对于100ask stm32mp157 pro开发板 需要先执行如下操作来使能4G模块使能引脚(默认系统会进行初始化操作)。
echo 82 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio82/direction
echo 1 > /sys/class/gpio/gpio82/value
echo 139 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio139/direction
echo 1 > /sys/class/gpio/gpio139/value
连接成功后内核会打印如下信息
[root@imx6ull:~]# [10445.035851] usb 1-1.2: new high-speed USB device number 5 using ci_hdrc
[10445.216275] option 1-1.2:1.0: GSM modem (1-port) converter detected
[10445.231992] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0
[10445.251340] option 1-1.2:1.1: GSM modem (1-port) converter detected
[10445.262084] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1
[10445.281795] option 1-1.2:1.2: GSM modem (1-port) converter detected
[10445.300860] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2
[10445.314912] option 1-1.2:1.3: GSM modem (1-port) converter detected
[10445.333545] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB3
如果您使用的是ML302 4G模块 连接好开发板并没有自动加载类似上述log 可以更新资料光盘最新系统 或者使用下述命令在开发板上执行 添加设备
echo 1782 4d10 > /sys/bus/usb-serial/drivers/generic/new_id
echo 1782 4d11 > /sys/bus/usb-serial/drivers/generic/new_id
echo 1782 4d12 > /sys/bus/usb-serial/drivers/generic/new_id
4G模块使用pppd拨号上网
使用中移 ML302 4G模块
1.在开发板/etc/ppp/目录下新建 chat-gprs-connect文件,使用vi 命令将下面的命令复制进去,并执行:wq保存退出
(注意下述配置为中国联通卡配置,如果您的是移动卡请参考注释把3GNET设置为CMNET)。
TIMEOUT 5
ECHO ON ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
ABORT '\nCOMMAND NO RESPONSE!\r'
'' \rAT
TIMEOUT 60
SAY "Press CTRL-C to break the connection process.\n"
OK 'ATE0'
#如果是移动卡,3GNET设置为CMNET
OK 'AT+CGDCONT=1,\"IP\",\"3GNET\"'
#如果是移动卡,ATD*99#设置为ATD*99***1#
OK 'ATD*99#'
TIMEOUT 60
SAY "Waiting for connect...\n"
CONNECT ''
SAY "connect Success!\n"
2.在开发板/etc/ppp/peers目录下新建 gprs 文件,使用vi 命令将下面的命令复制进去,并执行:wq保存退出。
/dev/ttyUSB0
115200
nocrtscts
nolock
local
debug
ipcp-accept-local
ipcp-accept-remote
nodetach
noauth
usepeerdns
defaultroute
0.0.0.0:0.0.0.0
connect '/usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect
开发板连接好4G模块后使用如下指令进行拨号上网,系统内默认支持的指令为中国联通,如果你使用的是并非是联通卡,请修改 /etc/ppp/gprs-connect-chat 文件内容为你SIM卡运营商的拨号上网指令,让后执行下面命令。
pppd call gprs > /dev/null &2>1
执行后如果有类似如下打印信息,表明4G模块拨号联网成功。
rcvd [IPCP ConfNak id=0x2 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
sent [IPCP ConfReq id=0x3 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
rcvd [IPCP ConfAck id=0x3 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.1.1
local IP address 10.136.179.50
remote IP address 10.64.64.64
primary DNS address 120.80.80.80
secondary DNS address 221.5.88.88
使用移远EC20 4G模块
1.在开发板 /etc/ppp/ 目录下新建 gprs-connect-chat 文件,使用vi 命令将下面的命令复制进去,并执行:wq保存退出。(注意下述配置为中国联通卡配置,如果您的是移动卡请参考注释把3GNET设置为CMNET)。
#Chat script for China Mobile, used SIMCOM sim4100 TD module.
TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rAT
OK ATS0=0
OK ATE0V1
#如果是移动卡,3GNET设置为CMNET
OK AT+CGDCONT=1,"IP","3GNET"
OK AT+CGEQREQ=1,2,128,384,,,0,,,,,,
OK ATDT*99*1#
CONNECT
2.在开发板/etc/ppp/peers目录下新建 gprsdial 文件,使用vi 命令将下面的命令复制进去,并执行:wq保存退出。
#/etc/ppp/peers/gprsdial
# This is pppd script for China Mobile, used SIMCOM SIM7100 Module
# Usage: root>pppd call gprs
#Interface should be used is the interface which connects physics interface of S
/dev/ttyUSB3
115200
crtscts
modem
#noauth
debug
nodetach
#hide-password
usepeerdns
noipdefault
defaultroute
user "cmnet"
0.0.0.0:0.0.0.0
#ipcp-accept-local
#ipcp-accept-remote
#lcp-echo-failure 12
#lcp-echo-interval 3
#noccp
#novj
#novjccomp
#persist
connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'
#disconnect '/bin/chat -v -f /etc/ppp/gprs-disconnect-chat'
执行pppd拨号命令
开发板连接好4G模块后使用如下指令进行拨号上网,系统内默认支持的指令为中国联通,如果你使用的是并非是联通卡,请修改/etc/ppp/gprs-connect-chat 文件内容为你SIM卡运营商的拨号上网指令,让后执行下面命令。
pppd call gprsdial > /dev/null &2>1
执行后如果有类似如下打印信息,表明4G模块拨号联网成功。
rcvd [IPCP ConfNak id=0x2 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
sent [IPCP ConfReq id=0x3 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
rcvd [IPCP ConfAck id=0x3 <addr 10.136.179.50> <ms-dns1 120.80.80.80> <ms-dns2 221.5.88.88>]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing existing default route via 192.168.1.1
local IP address 10.136.179.50
remote IP address 10.64.64.64
primary DNS address 120.80.80.80
secondary DNS address 221.5.88.88
测试4G模块是否可以联网通信
使用ifconfig命令查看是否出现一个 ppp 开头的网络设备,如下所示,我们4G模块使用的网卡接口为ppp0 ,接下来使用此接口测试是否可以ping通外网。
[root@imx6ull:~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:01:3F:2D:3E:4D
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth1 Link encap:Ethernet HWaddr 00:01:1F:2D:3E:4D
inet addr:192.168.1.21 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fdfd:3597:aa7a:0:201:1fff:fe2d:3e4d/64 Scope:Global
inet6 addr: fe80::201:1fff:fe2d:3e4d/64 Scope:Link
inet6 addr: fdfd:3597:aa7a::914/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:317 errors:0 dropped:0 overruns:0 frame:0
TX packets:211 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:99472 (97.1 KiB) TX bytes:27152 (26.5 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:5067 (4.9 KiB) TX bytes:5067 (4.9 KiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.136.179.50 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:62 (62.0 B) TX bytes:101 (101.0 B)
使用 ping -I ppp0 114.114.114.114
命令来指定使用ppp0接口单独去ping百度DNS地址,看是否可以联通,如果可以则会有如下提示。
[root@imx6ull:~]# ping -I ppp0 114.114.114.114
PING 114.114.114.114 (114.114.114.114): 56 data bytes
64 bytes from 114.114.114.114: seq=0 ttl=249 time=133.297 ms
64 bytes from 114.114.114.114: seq=1 ttl=249 time=96.049 ms
^C
--- 114.114.114.114 ping statistics ---
10 packets transmitted, 2 packets received, 80% packet loss
round-trip min/avg/max = 96.049/114.673/133.297 ms
[root@imx6ull:~]#
常用指令
移动拨号
#Chat script for China Mobile, used SIMCOM sim4100 TD module.
TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rAT
OK ATS0=0
OK ATE0V1
OK AT+CGDCONT=1,"IP","CMNET"
OK AT+CGEQREQ=1,2,128,384,,,0,,,,,,
OK ATDT*99*1#
CONNECT
联通拨号
#Chat script for China Mobile, used SIMCOM sim4100 TD module.
TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rAT
OK ATS0=0
OK ATE0V1
OK AT+CGDCONT=1,"IP","3GNET"
OK AT+CGEQREQ=1,2,128,384,,,0,,,,,,
OK ATDT*99*1#
CONNECT