How to use 4G Module on NanoPC-T4/zh

From FriendlyARM WiKi
Revision as of 01:32, 16 May 2019 by Tzs (Talk | contribs) (updated by API)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

English

1 Android下使用4G模块EC20

1.1 连接方法

连接时,需要通过USB to miniPCIe转接板转接EC20,再连接到主板的USB Host端口,如下图所示:

连接后无需额外的配置,启动Android后就可以使用4G上网了,跟Android手机类拟。

1.2 启用EC20的GPS功能

默认情况下,Android的GPS功能是关闭的 (原因是Android在没有找到任何GPS模块的情况下,会不停的打印LOG信息),在你连接了EC20模块后,就可以开启GPS了。
开启方法是修改Android源代码下的 vendor/quectel/ec20/BoardConfigPartial.mk 文件,将下面这行:

BOARD_HAS_GPS := false

改为

BOARD_HAS_GPS := true

然后重新编译 Android。

2 FriendlyDesktop下使用4G模块EC20

2.1 第1步:建立4G拨号

在FriendlyDesktop桌面右上角,点击网络图标,在弹出的菜单中选择“Edit connections”:
Friendlydesktop-4g-step1.jpg

2.2 第2步:创建4G连接

点击左下角的“+”加号按钮:
Friendlydesktop-4g-step2.jpg
在出现的菜单中选择"Mobile Broadband":
Friendlydesktop-4g-step2b.jpg

2.3 第3步:设置4G连接

在“Set up a Mobile Broadband Connection”中直接选择 “Next":
Friendlydesktop-4g-step2c.jpg
在出现的区域选择中,选择你所在的区域,我这里选择“China”,就会出现China的服务商,会列出中国移动和中国联通,我用的是中国移动的卡,所以选择"China mobile":
Friendlydesktop-4g-step2d.jpg
在“Choose your billing plan“对话框中,选择Internet,然后点Next:
Friendlydesktop-4g-step2d2.jpg
在确认的对话框中,点击 "Apply", 在下面的对话框中,点击"Save"保存设置:
Friendlydesktop-4g-step2e.jpg

2.4 第4步:拨号连接4G网络

在FriendlyDesktop桌面右上角,点击网络图标,在弹出的菜单中选择“Chine Mobile Internet 1",即可拨号到4G网络,如果弹出密码输入框,输入0000即可, 重启开发板会自动连接:
Friendlydesktop-4g-step4.jpg
下图是用4G网络浏览网页:
Friendlydesktop-4g-step4b.jpg

3 FriendlyCore下使用4G模块EC20

3.1 第1步:在开发板上编译quectel-CM命令行拨号程序

输入以下命令,编译并安装quectel-CM到 /usr/bin/ 目录:

git clone https://github.com/friendlyarm/quectel-cm.git
cd quectel-cm/
make
cp quectel-CM /usr/bin/

3.2 第2步:创建udhcpc script

quectel-CM程序会将运营商返回的IP、DNS等作为参数调用udhcpc script,这个脚本是不存在的,我们需要自已创建一个,请用你熟悉的编辑器创建一个新文件,文件名为:/usr/share/udhcpc/default.script,内容如下:

#!/bin/sh
 
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
 
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
 
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
 
case "$1" in
  deconfig)
    /sbin/ifconfig $interface 0.0.0.0
    ;;
 
  renew|bound)
    /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
 
    if [ -n "$router" ] ; then
      echo "deleting routers"
      while route del default gw 0.0.0.0 dev $interface ; do
        :
      done
 
      for i in $router ; do
        route add default gw $i dev $interface
      done
    fi
 
    echo -n > $RESOLV_CONF
    [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
    for i in $dns ; do
      echo adding dns $i
      echo nameserver $i >> $RESOLV_CONF
    done
    ;;
esac
 
exit 0

保存后,再用以下命令赋于可执行权限:

chmod 755 /usr/share/udhcpc/default.script

3.3 第3步:开始4G拨号

输入以下命令启动拨号:

quectel-CM &

拨号成功,屏幕会输出IP地址等信息,如下所示:

root@NanoPC-T4:~# quectel-CM &
[1] 5364
root@NanoPC-T4:~# [05-15_08:23:13:719] WCDMA&LTE_QConnectManager_Linux&Android_V1.1.34
[05-15_08:23:13:720] quectel-CM profile[1] = (null)/(null)/(null)/0, pincode = (null)
[05-15_08:23:13:721] Find /sys/bus/usb/devices/3-1 idVendor=2c7c idProduct=0125
[05-15_08:23:13:722] Find /sys/bus/usb/devices/3-1:1.4/net/wwan0
[05-15_08:23:13:722] Find usbnet_adapter = wwan0
[05-15_08:23:13:723] Find /sys/bus/usb/devices/3-1:1.4/usbmisc/cdc-wdm0
[05-15_08:23:13:723] Find qmichannel = /dev/cdc-wdm0
[05-15_08:23:13:739] cdc_wdm_fd = 7
[05-15_08:23:13:819] Get clientWDS = 18
[05-15_08:23:13:851] Get clientDMS = 2
[05-15_08:23:13:884] Get clientNAS = 2
[05-15_08:23:13:915] Get clientUIM = 1
[05-15_08:23:13:947] Get clientWDA = 1
[05-15_08:23:13:979] requestBaseBandVersion EC20CEFHLGR06A01M1G_OCPU_BETA1210
[05-15_08:23:14:043] requestSetEthMode QMUXResult = 0x1, QMUXError = 0x46
[05-15_08:23:14:075] requestGetSIMStatus SIMStatus: SIM_READY
[05-15_08:23:14:107] requestGetProfile[1] cmnet///0
[05-15_08:23:14:139] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[05-15_08:23:14:171] requestQueryDataCall IPv4ConnectionStatus: DISCONNECTED
[05-15_08:23:14:235] requestRegistrationState2 MCC: 460, MNC: 0, PS: Attached, DataCap: LTE
[05-15_08:23:14:938] requestSetupDataCall WdsConnectionIPv4Handle: 0xe16e4540
[05-15_08:23:15:002] requestQueryDataCall IPv4ConnectionStatus: CONNECTED
[05-15_08:23:15:036] ifconfig wwan0 up
[05-15_08:23:15:052] busybox udhcpc -f -n -q -t 5 -i wwan0
[05-15_08:23:15:062] udhcpc (v1.23.2) started
[05-15_08:23:15:077] Sending discover...
[05-15_08:23:15:093] Sending select for 10.22.195.252...
[05-15_08:23:15:105] Lease of 10.22.195.252 obtained, lease time 7200
[05-15_08:23:15:118] deleting routers
SIOCDELRT: No such process
[05-15_08:23:15:132] adding dns 221.179.38.7
[05-15_08:23:15:132] adding dns 120.196.165.7

3.4 测试4G连接

ping一个域名,看看DNS解析是否已经在工作了:

root@NanoPC-T4:~# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=56 time=74.3 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=2 ttl=56 time=25.1 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=3 ttl=56 time=30.8 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=56 time=29.1 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=5 ttl=56 time=29.2 ms

3.5 测试4G的网速

wget -O - https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python

得到的测试结果类拟如下这样:

Retrieving speedtest.net configuration...
Testing from China Mobile Guangdong (117.136.40.167)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by ChinaTelecom-GZ (Guangzhou) [2.51 km]: 62.726 ms
Testing download speed................................................................................
Download: 32.93 Mbit/s
Testing upload speed................................................................................................
Upload: 5.58 Mbit/s