树莓派使用EC20拨号上网

树莓派(Linux)使用EC20拨号上网

树莓派的镜像是Debian系列,说是在Linux拨号上网也无妨,本教程使用的拨号上网方式为PPP拨号,使用了移远官方的拨号脚本。附件如下:
EC20拨号上网设备驱动

一、EC20与树莓派连接

EC20与树莓派连接通用的方式是使用USB方式,有搭在核心板的 MiniPCIE接口
MiniPCIE接口

也有外置的USB接口,在某宝买一个底板回来就可以,基本上都通用。如下图为野火的4G模块底板。

野火4g模块底板

二、查看EC20设备

查看是否有EC20设备

lsusb

查看到有如下设备

pi@raspberrypi:~ $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 2c7c:0125 Quectel Wireless Solutions Co., Ltd. EC25 LTE modem
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2c7c:0125表示EC20设备。

使用dmesg命令查看usb设备

pi@raspberrypi:~ $ dmesg

[   10.269767] usbserial: USB Serial support registered for generic
[   10.274979] qmi_wwan 1-1.3:1.4: cdc-wdm0: USB WDM device
[   10.275857] qmi_wwan 1-1.3:1.4 wwan0: register 'qmi_wwan' at usb-0000:01:00.0-1.3, WWAN/QMI device, 72:f7:d5:12:f9:6c
[   10.275953] usbcore: registered new interface driver qmi_wwan
[   10.279927] usbcore: registered new interface driver option
[   10.279965] usbserial: USB Serial support registered for GSM modem (1-port)
[   10.280104] option 1-1.3:1.0: GSM modem (1-port) converter detected
[   10.282890] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB0
[   10.283292] option 1-1.3:1.1: GSM modem (1-port) converter detected
[   10.283689] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB1
[   10.284148] option 1-1.3:1.2: GSM modem (1-port) converter detected
[   10.284546] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB2
[   10.284809] option 1-1.3:1.3: GSM modem (1-port) converter detected
[   10.285296] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB3

可以看到,EC20在树莓派上映射出ttyUSB0、ttyUSB1、ttyUSB2、ttyUSB3一共四个串口。

查看串口信息

在/dev目录下查看串口的信息

pi@raspberrypi:~ $ ls /dev/ttyUSB*
/dev/ttyUSB0  /dev/ttyUSB1  /dev/ttyUSB2  /dev/ttyUSB3

可以看到有4个ttyUSB串口,它们的功能如下
ttyUSB1用作GPS信息接收、ttyUSB2是可以使用AT指令进行调试,ttyUSB3使用ppp拨号上网,

串口功能
ttyUSB0保留
ttyUSB1GPS信息接收
ttyUSB2AT指令进行调试
ttyUSB3ppp拨号上网或者AT指令进行调试

可以使用cutecom来进行AT调试,注意以下参数。
cutecom

三、拨号上网

下载上面的附件,在\Linux\USB\Quectel_WCDMA&LTE_Linux_USB_R01A01\linux-ppp-scripts_V1.2\linux-ppp-scripts目录下,可以看到有7个文件夹,
linux-ppp-scripts

博主将拨号脚本放在树莓派的家目录下~workdir/linux-ppp-scripts_V1.2linux-ppp-scripts/目录下。

pi@raspberrypi:~ $ ls ~/workdir/linux-ppp-scripts_V1.2/linux-ppp-scripts/
ip-up  quectel-chat-connect  quectel-chat-disconnect  quectel-ppp  quectel-pppd.sh  quectel-ppp-kill  readme

运行脚本

sudo bash ~/workdir/linux-ppp-scripts_V1.2/linux-ppp-scripts/quectel-pppd.sh

使用ifconfig查看网卡,会出现一个ppp0的网卡,
ifconifg
进行上网测试,使用ppp0网卡ping百度的网站

pi@raspberrypi:~ $ ping -I ppp0 www.baidu.com
PING www.a.shifen.com (14.215.177.38) from 100.92.173.146 ppp0: 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=52 time=215 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=52 time=117 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=52 time=101 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=52 time=124 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=52 time=107 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=52 time=105 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=7 ttl=52 time=128 ms
^C
--- www.a.shifen.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 15ms
rtt min/avg/max/mdev = 100.854/128.153/214.826/36.593 ms
pi@raspberrypi:~ $

总结

使用quectel-pppd.sh 拨号,命令形式如下:

sudo bash [目录]/quectel-pppd.sh 

串口设备名(比如/dev/ttyUSB3) APN username password(一般不做修改都可以拨号上网)

ip-up:pppd 在获取 ip 和 dns 之后,会自动调用这个脚本文件来设置系统的 DNS

嵌入式系统一般需要拷贝这个文件到 /etc/ppp 目录下。
请确保该文件在你的系统里有可执行权限。

quectel-ppp-kill 用来挂断拨号的,pppd必须被正常的挂断,否则可能会导致你下次ppp拨号失败。

使用下面方式来调用这个脚本

sudo bash [目录]/quectel-ppp-kill 

至此,可以使用4G模块上网了,如果树莓派同时连接了网线,网线的优先级大于4G模块,在使用网络是默认还是使用网线,可以拔掉网线或者将ppp0改为默认网卡。

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值