SIM900A/zh-hans

From BananaPro/Pi
Jump to: navigation, search
This page is a translated version of the page SIM900A and the translation is 92% complete.

Other languages:
English • ‎中文(简体)‎

准备

  1. LeMaker Guitar一块;
  2. SIM900A MINI V3.8.2模块;
  3. SIM电话卡一个。

线路连接

LeMaker Guitar-GPRS.png
LeMaker Guitar 40pin引脚上的UART0引脚,连接SIM900A模块上的串口。连接方式如下:

LeMaker Guitar底板B SIM900A
UART0_TX 3VR
UART0_RX 3VT
GND GND

LeMaker Guitar 40pin引脚参考: http://wiki.lemaker.org/images/f/f4/Image008%2811-05-13-42-56%29.png.

LeMaker Guitar 40pin引脚上的UART0对应的设备文件是:/dev/ttyS0。因此我们在LeMaker Guitar上使用minicom -s命令打开串口,这里需要设置串口为:/dev/ttyS0,并设置串口参数为:9600N81。打开串口后,我们就可以在minicom中向GPRS模块发送AT指令了。

常用AT命令

1.第一个AT命令,同步波特率:

AT

2.查询信号质量:

AT+CSQ

3.查询SIM卡状态:

AT+CPIN?

4.查询当前运营商:

AT+COPS?

5.查询模块制造商:

AT+CGMI

6.查询模块型号:

AT+ CGMM

7.查询产品序列号(IMEI 号):

AT+ CGSN

8.查询本机号码:

AT+ CNUM

9.设置回显模式:

ATE1

更多指令请参考:http://www.cnblogs.com/jinweida/archive/2009/09/27/1574843.html

拨打电话

ATE1 #设置回显方式;
AT+COLP=1 #设置被叫号码显示;
ATD10010; #拨打电话号码,ADT+电话号码;,这里句末一定要加“;”号;
AT+VTS=1 #通话结束,可查询本机号码;
ATH #挂断电话

下面是一次拨打电话过程:

ATE1
OK
AT+COLP=1
OK
ATD10010;
+COLP: "10010",129,"",0,""
OK
AT+VTS=1
OK
ATH
OK

接听电话

AT+CLIP=1 #开启来电显示功能
ATA #接听电话
ATH #主动挂断电话

下面是一次接听电话过程:

AT+CLIP=1
OK
RING
+CLIP: "1351092****",161,"",,"",0
RING
+CLIP: "1351092****",161,"",,"",0
RING
+CLIP: "1351092****",161,"",,"",0
ATA
OK
ATH
OK

接收短信

AT+CMGF=1 # 设置文本模式;
AT+CSCS="GSM" # 设置GSM字符集;
AT+CNMI=2,1 # 设置新消息提示;
AT+CMGR=3 # 信息存放在SIM卡3位置,读取短信。

下面是一次接收短信过程:

AT+CMGF=1
OK
AT+CSCS="GSM"
OK
AT+CNMI=2,1
OK
+CMTI: "SM",3
AT+CMGR=3
+CMGR: "REC UNREAD","1351092****","","16/01/08,11:18:02+32"
hello
OK

发送短信

AT+CSCS="GSM" # 设置GSM字符集;
AT+CMGF=1 # 设置文本模式;
AT+CMGS="1351092****" # 发送消息给1351092****;
Ctr+z # “Ctr+z”操作,发送信息。

下面是一次发送短信过程:

AT+CSCS="GSM"
OK
AT+CMGF=1
OK
AT+CMGS="1351092****"
> Hello,this is John.web                        #“Ctr+z”,send message
+CMGS: 200
OK

发送中文短信

AT+CMGF=1 # 设置文本模式;
AT+CSMP=17,167,2,25 # 设置文本模式参数;
AT+CSCS="UCS2" # 设置为UCS2字符集编码;
AT+CMGS="00310033003500310030003900320035003200330030" # 使用UNICODE编码,发送消息给1351092****;
Ctr+z #“Ctr+z”操作,发送信息。

下面是一次发送中文短信过程:

AT+CMGF=1
OK
AT+CSMP=17,167,2,25
OK
AT+CSCS="UCS2"
OK
AT+CMGS="00310033003500310030003900320035003200330030"
> 4F60597D        #“你好”UNICODE coding,“Ctr+z”,send message
+CMGS: 201
OK


TCP通信

AT+CGCLASS="B" # 设置移动台类别为B;
AT+CGDCONT=1,"IP","CMNET" # 置PDP上为 1,采用互联网协议( IP),接入点为"CMNET";
AT+CGATT=1 # 附着 GPRS 业务;
AT+CIPCSGP=1,"CMNET" # 设置为GPRS 连接;
AT+CLPORT="TCP","2000" # 设置本地 TCP 连接端口为2000;
AT+CIPSTART="TCP","johnweiwen.6655.la","28255" # 建立 TCP 连接,连接到:johnweiwen.6655.la,连接端口为:28255;
AT+CIPSEND # 开始发送数据,模块返回:>,提示输入发送内容;
Ctr+z # “Ctr+z”操作,发送信息;
AT+CIPCLOSE=1 # 闭当前TCP连接;connection
AT+CIPSHUT # 关闭场景


因为没有公网IP地址,因此使用“花生壳”(内网版)获取一个免费的域名,并映射到内网的IP地址,即本人电脑的IP地址:192.168.0.61。
花生壳下载地址:http://hsk.oray.com/download/#type=windows|lan
Guitar TCP 1.png

Guitar TCP 2.png

PC端使用网络调试助手建立TCP服务,并设置端口地址为:8090
Guitar TCP 3.png

minicom端一次TCP通信过程:

AT+CGCLASS="B"                                       
OK
AT+CGDCONT=1,"IP","CMNET"               
OK
AT+CGATT=1                                                
OK
AT+CIPCSGP=1,"CMNET"               
OK
AT+CLPORT="TCP","2000"                        
OK
AT+CIPSTART="TCP","johnweiwen.6655.la","28255"        
OK
CONNECT OK        
AT+CIPSEND                                                
>Hello,this is SIM900A                # "Ctr+z",send SMS
SEED OK
Hello,this is sscom                   # Receive the data from Network debugging assistant.
AT+CIPCLOSE=1
CLOSE OK                                       
AT+CIPSHUT
OK

使用wiringlmk发送AT指令

在Lemuntu系统上安装软件源

wget http://archive.lemaker.org/lemuntu/key/deb.gpg.key -O - | apt-key addcd /etc/apt/sources.list.d/
sudo vim lemuntu.list

Add the content as below:

deb http://archive.lemaker.org/lemuntu/ jessie main
sudo apt-get update

安装wiringlmk

sudo apt-get install wiringlmk

编辑测试代码GPRS_Test.c

#include <stdio.h>
#include <stdlib.h>
#include <wiringSerial.h>
 
int main()
{
        int fd;
        char string[1024];
 
        if((fd=serialOpen("/dev/ttyS0",9600))<0)
        {
                printf("Can't Open /dev/ttyS0,fd=%d\n",fd);
                exit(-1);
        }
 
        printf("SEND:AT\n");        
        serialPuts(fd,"AT");
        serialPrintf(fd,string);
        printf("GET:%s\n",string);
 
        printf("SEND:AT+CNUM\n");        
        serialPuts(fd,"AT+CNUM");
        serialPrintf(fd,string);
        printf("GET:%s\n",string);
 
 
        serialClose(fd);
        return 0;
}

编译代码,生成可执行文件

gcc -o GPRS_Test GPRS_Test.c -I/usr/local/include -L/usr/local/lib -lwiringPi