移远EC200U-CN AA在树莓派下使用
EC200U-CN AA是个USB Dongle,除了支持Cat 1的LTE以外,还支持GPS/北斗等GNSS,价格便宜,合适放到树莓派上当移动数据使用。
设备在树莓派下会被识别成cdc_ether
的设备,官方并没有提供树莓派的使用文档,给过来的Linux脚本设备名称也不对,网上看了不少文档,结果发现走了很多弯路。
首先需要把模块给识别成USB Serial
,加载成功后,会识别出ttyUSB0
-ttyUSB7
共8个设备。官方的脚本里面调用的是ttyUSB3
,这个端口不对(应该是GPS的端口),直接用ttyUSB0
就可以了。
先lsusb
看看设备是否被识别
pi@raspberrypi:~ $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 2c7c:0901 Quectel Wireless Solutions Co., Ltd. Android
Bus 001 Device 003: ID 0bda:2832 Realtek Semiconductor Corp. RTL2832U DVB-T
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
可以看到设备的ID是2c7c:0901
然后把设备添加进USB Serial
pi@raspberrypi:~ $ sudo modprobe option
pi@raspberrypi:~ $ sudo chmod 777 /sys/bus/usb-serial/drivers/option1/new_id
pi@raspberrypi:~ $ sudo echo '2c7c 0901' > /sys/bus/usb-serial/drivers/option1/new_id
dmesg
看下,设备已经被正确识别
[ 1058.520201] usbcore: registered new interface driver usbserial_generic
[ 1058.520269] usbserial: USB Serial support registered for generic
[ 1058.542165] usbcore: registered new interface driver option
[ 1058.542251] usbserial: USB Serial support registered for GSM modem (1-port)
[ 1064.925797] option 1-1.2:1.2: GSM modem (1-port) converter detected
[ 1064.926232] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0
[ 1064.926565] option 1-1.2:1.3: GSM modem (1-port) converter detected
[ 1064.926933] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1
[ 1064.927247] option 1-1.2:1.4: GSM modem (1-port) converter detected
[ 1064.927591] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB2
[ 1064.927962] option 1-1.2:1.5: GSM modem (1-port) converter detected
[ 1064.928430] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB3
[ 1064.928779] option 1-1.2:1.6: GSM modem (1-port) converter detected
[ 1064.929149] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB4
[ 1064.929468] option 1-1.2:1.7: GSM modem (1-port) converter detected
[ 1064.929873] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB5
[ 1064.930210] option 1-1.2:1.8: GSM modem (1-port) converter detected
[ 1064.930618] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB6
[ 1064.930938] option 1-1.2:1.9: GSM modem (1-port) converter detected
[ 1064.931278] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB7
pi@raspberrypi:~ $ ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 /dev/ttyUSB4 /dev/ttyUSB5 /dev/ttyUSB6 /dev/ttyUSB7
接下来要把设备PPP拨号连上网,有两种方法:
第一种简单粗暴,直接发送AT指令,然后通过DHCP client获取IP
pi@raspberrypi:~ $ echo -e "AT+QCFG=\"usbnet\",3\n\n" > /dev/ttyUSB0
pi@raspberrypi:~ $ echo -e "AT+qnetdevctl=1,1\n\n" > /dev/ttyUSB0
pi@raspberrypi:~ $ sudo udhcpc -i usb0
udhcpc: started, v1.30.1
No resolv.conf for interface usb0.udhcpc
udhcpc: sending discover
udhcpc: sending select for 10.11.1.142
udhcpc: lease of 10.11.1.142 obtained, lease time 30840
pi@raspberrypi:~ $ ifconfig -a
...
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.11.1.142 netmask 255.255.255.0 broadcast 10.11.1.255
inet6 fe80::xxxx:xxxx:xxxx:xxxx prefixlen 64 scopeid 0x20<link>
ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)
RX packets 14 bytes 2485 (2.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64 bytes 7929 (7.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
...
第二种就是用官方给的Linux拨号脚本(找淘宝卖家要),但需要把quectel-ppp
和quectel-ppp.sh
里面的/dev/ttyUSB3
改为/dev/ttyUSB0
如果需要随树莓派系统一起启动,那么编辑/etc/rc.local
,在exit 0
前面加上下面的内容
sudo modprobe option
sudo chmod 777 /sys/bus/usb-serial/drivers/option1/new_id
sudo echo '2c7c 0901' > /sys/bus/usb-serial/drivers/option1/new_id
/etc/ppp/peers/quectel-pppd.sh & #这里改为自己喜欢的启动方式
附上一些测试命令(需要安装minicon并且使用minicon -s
配置好)
minicon -D /dev/ttyUSB1 测试4G模块
AT测试指令:
AT 测试AT指令功能是否正常 (OK)
AT+CPIN? 查询SIM卡是否正+CPIN:READY OK)
AT+CSQ 查询模组的信号Q:22,99)
AT+CREG? 查询模组是否注册上GSM (+CREG:0,1 ) 表示已注册上
AT+CGREG? 查询模组是否注册上GPRS (+CGREG:0,1 ) 表示已注册上
AT+QICSGP=1,1,"IP","CMNETCET" GPRS的APN,移动 CMNET,联通 UNINET
AT+QIDEACT=1 在激活GPRS场景之前先关闭GPRS场景,确保连接正确
AT+QIACT=1 激活GPRS移动场景
////-------------------- PPP 设置流程 -----------------------
AT+CGREG? 查询模组是否注册上GPRS (+CGREG:0,1 ) 表示已注册上
AT+CGDCONT=1,"IP,"CMNET" 为 PPP 设置 AP
ATD*99# 启动 PPP