SIM900A

From BananaPro/Pi
Jump to: navigation, search

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

Prepare

  1. a LeMaker Guitar Base Board Rev.B
  2. a SIM900A MINI V3.8.2
  3. a SIM card

Connect

LeMaker Guitar-GPRS.png
There has a UART0 on LeMaker Guirar Base Board ReV.B's 40pins GPIO, We can connect Guitar's UART0 to SIM900A.
Connection mode as follows:

LeMaker Guitar Base Board Rev.B SIM900A
UART0_TX 3VR
UART0_RX 3VT
GND GND

As to LeMaker Guirar Base Board ReV.B's 40pins GPIO,please refer to http://wiki.lemaker.org/images/f/f4/Image008%2811-05-13-42-56%29.png.

The device file node of UART0 is /dev/ttyS0. So we use the command "minicom -s" to open the serial port, and set Serial Device:/dev/ttyS0; Bps/Par/Bits:9600N81.And the we can send AT commands to GPRS module in minicom.

Common AT commands

1. The first AT command, sync baudrate:

AT

2. Qurey signal quality:

AT+CSQ

3. Query SIM card state:

AT+CPIN?

4. Query the current operators:

AT+COPS?

5. QueryQuery module manufacturers:

AT+CGMI

6. Query module type:

AT+ CGMM

7. Query IMEI number:

AT+ CGSN

8. Query the phone number:

AT+ CNUM

9. Set echo mode:

ATE1

More AT commands, please refer to http://www.cnblogs.com/jinweida/archive/2009/09/27/1574843.html

Call phone

ATE1 # Set echo mode;
AT+COLP=1 # Set called phone number display;
ATD10010; # Call phone number, ADT+phone number, must add ";" on the end of a sentence;
AT+VTS=1 # When call end,qurey the phone number;
ATH # hang up.

Once call process as below:

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

Answer the phone

AT+CLIP=1 # Open the call ID
ATA # Answer the phone
ATH # Hang up the phone

Once call process as below:

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

Receive SMS

AT+CMGF=1 # Set text mode
AT+CSCS="GSM" # Set GSM character set
AT+CNMI=2,1 # Set a new message prompt
AT+CMGR=3 # Information was stored in the 3th SIM card, read SMS

Once receive SMS as below:

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

Send SMS

AT+CSCS="GSM" # Set GSM character set
AT+CMGF=1 # Set text mode
AT+CMGS="1351092****" # Send mesage to 1351092****
Ctr+z #“Ctr+z”,send message

Once send SMS as below:

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

Send Chinese SMS

AT+CMGF=1 # Set text mode
AT+CSMP=17,167,2,25 # Set the text mode parameter
AT+CSCS="UCS2" # Set to UCS2 character set encoding
AT+CMGS="00310033003500310030003900320035003200330030" # Use UNICODE coding,send message to 1351092****
Ctr+z #“Ctr+z”,send message

Once send chinese SMS as below:

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 communication

AT+CGCLASS="B" # Set the mobile station type B
AT+CGDCONT=1,"IP","CMNET" # Set PDP:1, adapt IP, Access point:"CMNET"
AT+CGATT=1 # Attach GPRS service
AT+CIPCSGP=1,"CMNET" # Set GPRS connection
AT+CLPORT="TCP","2000" # Set TCP connection port: 2000
AT+CIPSTART="TCP","johnweiwen.6655.la","28255" # Create TCP connection, connect to johnweiwen.6655.la, connection port:28255
AT+CIPSEND # Start to send data, GPRS module return:>, prompt to send content.
Ctr+z # "Ctr+z",send message
AT+CIPCLOSE=1 # Clsoe TCP connection
AT+CIPSHUT # Clsoe scenes


Since I do not have the public IP address, So we use Peanut Shell(Intranet edition) to get a free domain name, and the map the domain name to local IP.
Peanut Shell download:http://hsk.oray.com/download/#type=windows|lan
Guitar TCP 1.png

Guitar TCP 2.png

We use Network debugging assistant to create TCP service, and set port:8090.
Guitar TCP 3.png

Once TCP communication process as below:

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

Use wiringlmk to send AT commands

Install software source on 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

Install wiringlmk

sudo apt-get install wiringlmk

Edit the test code

#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;
}

Compile the test code

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