SIM7600CE聯網測試分爲兩部分:html
一、TCP/IP鏈接node
二、PPP撥號上網python
實驗環境:ubuntu-meta 16.04linux
硬件:樹莓派3B,SIM7600CEubuntu
上網卡:移動的NB-IOT物聯網卡ide
微雪官方教程:http://www.waveshare.net/wiki/SIM7600CE_4G_HAT工具
把模塊插入到樹莓派,並USB接口連到樹莓派USB口上,開機,以下圖所示:測試
SIM7600X 4G HAT板載樹莓派GPIO接口,可直接插入各版本樹莓派使用;下表爲樹莓派管腳與模塊引腳鏈接狀況(樹莓派三代B 和 樹莓派三代B+):this
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模塊以前,須要對樹莓派初始化設置spa
cd /home/pi/SmartIoTControlSystem/SIM7600X/c
chmod 777 sim7600_4G_hat_init
sudo nano /etc/rc.local
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,minicom是linux平臺串口調試工具:
sudo apt-get install minicom
三、執行minicom -D /dev/ttyS0(ttyS0爲樹莓派3B/3B+的串口)。
默認波特率爲115200
樹莓派2B/zero,用戶串口設備號爲ttyAMA0,樹莓派3B/3B+串口設備號爲ttyS0。
四、以AT同步測試爲例,發送相關指令,以下圖所示:
sudo minicom -D /dev/ttyS0
到此,SIM7600的初始化完成!
1. TCP/IP鏈接測試
C語言版:
一、將模塊插入樹莓派中;
二、下載示例程序,把整個SIM7600X文件夾複製到/home/pi/SmartIoTControlSystem 路徑下;
三、進入到bcm2835目錄,編譯安裝BCM2835庫:
cd /home/pi/SmartIoTControlSystem/SIM7600X/c/bcm2835
chmod +x configure && ./configure && sudo make && sudo make install
說明:若是編譯出現問題,請參考FAQ的說明操做。
四、分別進到對應實例目錄下,編譯和運行程序,相關指令說明以下(以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
成功!