SIM7600CE聯網測試分為兩部分:
1、TCP/IP連接
2、PPP撥號上網
實驗環境:ubuntu-meta 16.04
硬件:樹莓派3B,SIM7600CE
上網卡:移動的NB-IOT物聯網卡
微雪官方教程:http://www.waveshare.net/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 for a dialup connection authenticated with PAP or CHAP # # This is the default configuration used by pon(1) and poff(1). # See the manual page pppd(8) for information 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 password in /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 initialization string. connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs" # Serial device to which the modem is connected. /dev/ttyUSB2 #由於我們使用SIM7600CE的4G模塊,並且該模塊的驅動已經默認添加到raspbian的內核的,ttyUSB2為ppp的撥號端口 # Speed of the serial line. 115200 nocrtscts #增加 debug #增加 nodetach #增加 ipcp-accept-local #增加 ipcp-accept-remote #增加 # Assumes that your IP address is allocated dynamically by the ISP. noipdefault # Try to get the name server addresses from the ISP. usepeerdns # Use this connection as the default route. defaultroute # Makes pppd "dial again" when the connection is lost. 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,99 OK AT+CPIN? +CPIN: READY OK AT+COPS? +COPS: 1,0,"CHINA MOBILE CMCC",7 OK AT+CREG? +CREG: 0,1 OK AT+CPSI? +CPSI: LTE,Online,460-00,0x69B1,132648988,136,EUTRAN-BAND40,38950,5,5,-65,-988,8 OK AT+CEREG? +CEREG: 0,1 OK
調試完成退出。
查看網卡信息
ifconfig
開始撥號
pppd call gprs
撥號成功!
再次查看網卡信息:
可以看到多出ppp0網卡,即成功撥號,並獲得一個臨時IP。
使用 指定網卡進行ping操作 測試ppp0網卡是否可以連通外網
eth0網卡測試:
ping -I 192.168.1.179 www.baidu.com
成功!
ppp0網卡測試:
ping -I 100.104.6.86 www.baidu.com
無法ping通!
因為初次,撥號上網后,DNS無法解析,上不了網,可以加上指令:
route add -net 0.0.0.0 ppp0
成功!