SIM7600CE联网测试分为两部分:
1、TCP/IP连接
2、PPP拨号上网
实验环境:ubuntu-meta 16.04
硬件:树莓派3B,SIM7600CE
上网卡:移动的NB-IOT物联网卡
微雪官方教程:/wiki/SIM7600CE_4G_HAT
把模块插入到树莓派,并USB接口连到树莓派USB口上,开机,如下图所示:
硬件连接
SIM7600X 4G HAT板载树莓派GPIO接口,可直接插入各版本树莓派使用;下表为树莓派管脚与模块引脚连接情况(树莓派三代B 和 树莓派三代B+):
SIM7600X 4G HAT
Raspberry Pi
5V
5V
GND
GND
RXD
TXD (对应BCM的14)
TXD
RXD (对应BCM的15)
PWR
P22 (对应BCM的P6)
FLIGHTMODE
P7 (对应BCM的P4),当拉高时进入飞行模式
树莓派初始化设置
使用SIM7600CE模块之前,需要对树莓派初始化设置
下载示例程序,解压后,把Raspberry目录下的 c 改名为SIM7600X,然后整个文件夹复制到/home/pi/ 路径下,
命令行进入到/home/pi/目录下,执行指令
cd /home/pi/SmartIoTControlSystem/SIM7600X/c
chmod 777 sim7600_4G_hat_init
设置开机初始化脚本,运行命令:
sudo nano /etc/rc.local
在exit 0前面加入 (如下图所示):
sh /home/pi/SmartIoTControlSystem/SIM7600X/c/sim7600_4G_hat_init
树莓派串口配置
由于树莓派串口默认用于终端调试,如需使用串口,则需要修改树莓派设置。执行如下命令进入树莓派配置:
sudo raspi-config
选择Interfacing Options ->Serial ->no -> yes,关闭串口调试功能。
打开/boot/config.txt文件,找到如下配置语句使能串口,如果没有,可添加在文件最后面:
sudo nano /boot/config.txt
重启生效。
树莓派minicom串口调试
1、将模块插入树莓派中
2、安装minicom,minicom是linux平台串口调试工具:
sudo apt-get install minicom
3、执行minicom -D /dev/ttyS0(ttyS0为树莓派3B/3B+的串口)。
默认波特率为115200
树莓派2B/zero,用户串口设备号为ttyAMA0,树莓派3B/3B+串口设备号为ttyS0。
4、以AT同步测试为例,发送相关指令,如下图所示:
sudo minicom -D /dev/ttyS0
到此,SIM7600的初始化完成!
1. TCP/IP连接测试
C语言版:
1、将模块插入树莓派中;
2、下载示例程序,把整个SIM7600X文件夹复制到/home/pi/SmartIoTControlSystem路径下;
3、进入到bcm2835目录,编译安装BCM2835库:
cd /home/pi/SmartIoTControlSystem/SIM7600X/c/bcm2835
chmod +x configure && ./configure && sudo make && sudo make install
说明:如果编译出现问题,请参考FAQ的说明操作。
4、分别进到对应实例目录下,编译和运行程序,相关指令说明如下(以TCP程序为例):
sudo make clean //清除原来的执行文件
sudo make //重新编译
sudo ./TCP //运行程序
上述命令组合使用:
sudo make clean && sudo make && sudo ./TCP
微雪官网给的python例子需要python3环境,而现在的环境为python2,不再测试。
2. ppp拨号软件安装与配置
安装ppp
sudo apt-get install ppp
新建一个script脚本
sudo su
cd /etc/ppp/peers
cp provider gprs
修改gprs配置文件
nano gprs
修改内容如下:
# example configuration fora dialup connection authenticated with PAP or CHAP
#
# Thisis the default configuration used by pon(1) and poff(1).
# See the manual page pppd(8) forinformation on all the options.
# MUST CHANGE: replace myusername@realm with the PPP login name given to
# your by your provider.
# There should be a matching entry with the passwordin /etc/ppp/pap-secrets
# and/or /etc/ppp/chap-secrets.
user"myusername@realm"# MUST CHANGE: replace********with the phone number of your provider.
# The/etc/chatscripts/pap chat script may be modified to change the
# modem initializationstring.
connect"/usr/sbin/chat -v -f /etc/chatscripts/gprs"# Serial device to which the modemisconnected./dev/ttyUSB2 #由于我们使用SIM7600CE的4G模块,并且该模块的驱动已经默认添加到raspbian的内核的,ttyUSB2为ppp的拨号端口
# Speed of the serial line.115200nocrtscts #增加
debug #增加
nodetach #增加
ipcp-accept-local #增加
ipcp-accept-remote #增加
# Assumes that your IP addressisallocated dynamically by the ISP.
noipdefault
# Try toget the name server addresses fromthe ISP.
usepeerdns
# Usethis connection as the defaultroute.
defaultroute
# Makes pppd"dial again" when the connection islost.
persist
# Do not ask the remote to authenticate.
noauth
查看SIM7600CE的串口
ls /dev/ttyUSB*
使用minicom串口调试工具简单测试(如果未安装使用 sudo apt-get install minicom 进行安装)
连接 /dev/ttyUSB2 串口调试
minicom -D /dev/ttyUSB2
调试过程如下:
AT
OK
AT+CSQ+CSQ: 21,99OK
AT+CPIN?
+CPIN: READY
OK
AT+COPS?
+COPS: 1,0,"CHINA MOBILE CMCC",7OK
AT+CREG?
+CREG: 0,1OK
AT+CPSI?
+CPSI: LTE,Online,460-00,0x69B1,132648988,136,EUTRAN-BAND40,38950,5,5,-65,-988,8OK
AT+CEREG?
+CEREG: 0,1OK
调试完成退出。
查看网卡信息
ifconfig
开始拨号
pppd call gprs
拨号成功!
再次查看网卡信息:
可以看到多出ppp0网卡,即成功拨号,并获得一个临时IP。
使用指定网卡进行ping操作测试ppp0网卡是否可以连通外网
eth0网卡测试:
ping -I 192.168.1.179
成功!
ppp0网卡测试:
ping -I 100.104.6.86
无法ping通!
因为初次,拨号上网后,DNS无法解析,上不了网,可以加上指令:
route add -net 0.0.0.0 ppp0
成功!