SIM900_TCPIP_Application
Note_V1.02
AN_SIM900_TCPIP_V1.02 1 2011.04.01
Smart Machine Smart Decision
Document Title:
Version:
Date:
Status:
TCPIP Application Note
1.02
2011-4-1
Release
AN_SIM900_TCPIP_Application Note_V1.02
Document Control ID:
General Notes
SIMCom offers this information as a service to its customers, to support application and
engineering efforts that use the products designed by SIMCom. The information provided is based
upon requirements specifically provided to SIMCom by the customers. SIMCom has not
undertaken any independent search for additional relevant information, including any information
that may be in the customer’s possession. Furthermore, system validation of this product designed
by SIMCom within a larger electronic system remains the responsibility of the customer or the
customer’s system integrator. All specifications supplied herein are subject to change.
Copyright
This document contains proprietary technical information which is the property of SIMCom
Limited., copying of this document and giving it to others and the using or communication of the
contents thereof, are forbidden without express authority. Offenders are liable to the payment of
damages. All rights reserved in the event of grant of a patent or the registration of a utility model
or design. All specification supplied herein are subject to change without notice at any time.
Copyright © Shanghai SIMCom Wireless Solutions Ltd. 2011
AN_SIM900_TCPIP_V1.02 1 2011.04.01
Smart Machine Smart Decision
Contents
2.3
3.1
3.2
2.1.1
2.1.2
2.1.3
2.1.4
2.2.1
2.2.2
2.2.3
2.2.4
2.2.5
Version history..................................................................................................................................3
1
Structure....................................................................................................................................4
Single Connection.....................................................................................................................5
2
Non-transparent mode...................................................................................................5
2.1
How to Establish a TCP Client Connection ......................................................5
How to Establish a UDP Client Connection......................................................7
How to Establish a TCP Server Connection......................................................8
UDP Extended Mode ........................................................................................9
Transparent Mode .......................................................................................................11
What is Transparent Mode ..............................................................................11
How to Configure Transparent Mode..............................................................11
How to Establish Connection under Transparent Mode..................................11
How to Switch Between Data Mode and Command Mode.............................12
How to handle incoming call and short message in data mode.......................13
Fix Local Port of TCP/UDP Client .............................................................................13
3 Multi Connection ....................................................................................................................14
As a Client...................................................................................................................14
As a TCP Server..........................................................................................................16
4 DNS Function .........................................................................................................................19
5 Data Sending Related..............................................................................................................20
Fixed Length Sending .................................................................................................20
Timed Sending ............................................................................................................20
Query Available Data Length to be Sent.....................................................................20
Select Data Transmitting Mode...................................................................................21
Query Data Transmitting Amount...............................................................................21
6 Data Receiving Related...........................................................................................................23
Receive Data Automatically........................................................................................23
Receive Data Manually...............................................................................................23
7 GPRS States Exchange Related ..............................................................................................25
8 Connection Closing Related....................................................................................................27
9 Connection Activity Checking Related...................................................................................27
10 Power Consumption with Existing Connection ......................................................................27
11 Error Handling ........................................................................................................................28
Appendix.........................................................................................................................................29
A. Related Documents .........................................................................................................29
B. Conventions and Abbreviations ......................................................................................29
2.2
5.1
5.2
5.3
5.4
5.5
6.1
6.2
AN_SIM900_TCPIP_V1.02 2011.04.01
2
Smart Machine Smart Decision
Version history
Version Description of change
1.01
1.02
Added “UDP Extended Mode”
Added CIPRXGET application in chapter 6.2
Author
Chenyang
Date
2010-6-22
2011-4-1
SCOPE
This document describes how to use the internal TCPIP stack of SIM900 through AT commands.
Examples are also given for reference.
This document can be used for SIM900 serial modules, like SIM900, SIM900D, SIM900B and
SIM900A.
This document is subject to change without notice at any time.
AN_SIM900_TCPIP_V1.02 2011.04.01
3
Smart Machine Smart Decision
1 Structure
There are two modes of connection for SIM900 TCP/IP application: Single connection and Multi
connection. When in single connection mode, SIM900 can work at both transparent mode and
non-transparent mode; and under these two transmission modes, SIM900 can be configured as
either TCP/UDP client or TCP server. When in multi connection mode, SIM900 can only work at
non-transparent mode. In this mode, SIM900 can work as an absolute TCP/UDP client, which can
establish 8 connections in total. In this mode, it can also be configured as one TCP server, which
allows 7 TCP/UDP clients to be connected; and the TCP server also can act as a client,
establishing 7 connections to one remote server. The structure of the TCP/IP application is given
as below.
Figure1: SIM900 TCPIP Structure
AN_SIM900_TCPIP_V1.02 2011.04.01
4
Smart Machine Smart Decision
2 Single Connection
Command AT+CIPMUX= is used for selecting TCPIP connection mode, when n=0, it is
single connection; when n=1, it is multi connection. The default configuration is single connection
mode. For single connection, SIM900 supports both transparent mode and non-transparent mode.
2.1 Non-transparent mode
Command AT+CIPMODE= is used for selecting TCPIP application mode, when n=0, it is
non-transparent mode (normal mode); when n=1, it is transparent mode. The default configuration
is non-transparent mode. There are three working modes for SIM900 under this mode: TCP client,
UDP client and TCP server.
2.1.1 How to Establish a TCP Client Connection
Firstly, before any TCP/UDP related operation is set up, the module should be connected to GSM
or GPRS network. User can use the commands “AT+CREG?” and “AT+CGATT?” to query the
GSM network registration status whether the module has been attached to GPRS service.
AT+CPIN?
+CPIN: READY
OK
AT+CSQ
CSQ: 20,0
OK
AT+CREG?
+CREG: 0,1
OK
AT+CGATT?
+CGATT: 1
OK
Secondly, user should use the command group AT+CSTT, AT+CIICR and AT+CIFSR to start
the task and activate the wireless connection. Lastly, user can establish TCP connection between
SIM900 and the server by AT command (AT+CIPSTART=”TCP”,”IP Address of server”, “port
AN_SIM900_TCPIP_V1.02 2011.04.01
5
Smart Machine Smart Decision
number of server”). If the connection is established successfully, response “CONNECT OK” will
come up from the module. Now user can send data to the server with “AT+CIPSEND”.
“AT+CIPSEND” will return promoting mark “>”, user should write data after “>” then issue
CTRL+Z (0x1a) to send. If sending is successful, it will respond “SEND OK”. And if there is data
coming from the server, the module will receive the data automatically from the serial port. User
can close the TCP connection with “AT+CIPCLOSE” command. Below is an example of TCP
connection to remote server.
AT+CGATT?
+CGATT: 1
OK
AT+CSTT=”CMNET” // Start task and set APN. See Note [1].
OK
AT+CIICR // Bring up wireless connection (GPRS or CSD)
OK
AT+CIFSR // Get local IP address
10.78.245.128
AT+CIPSTART=”TCP”,”116.228.221.51”, “8500” // Start up the connection
OK
CONNECT OK // The TCP connection has been established
successfully.
AT+CIPSEND
> hello TCP server //Send data to remote server, CTRL+Z (0x1a) to
send. See Note[2]
SEND OK // Remote server receives data.
hello sim900 // Received data from remote server
CLOSED // Remote server closed the connection
Note [1]: The default APN is “CMNET”, with no username or password. Check with local GSM
provider to get the APN.
Note [2]: User should write data only after the promoting mark “>” , and then use CTRL+Z to
send. User can use command “AT+CIPSPRT” to set whether echo promote “>” after issuing
AN_SIM900_TCPIP_V1.02 2011.04.01
6
Smart Machine Smart Decision
“AT+CIPSEND”.
2.1.2 How to Establish a UDP Client Connection
The process of establishing UDP connection is similar to TCP.
AT+CGATT?
+CGATT: 1
OK
AT+CSTT=”CMNET”
OK
AT+CIICR
OK
AT+CIFSR
10.77.65.18
AT+CIPSTART=”UDP”,”116.228.221.51”,”9600”
CONNECT OK
AT+CIPSEND
> sim900 UDP test
SEND OK // Data has been sent out from the serial
port, but it is unknown if the data
reaches the UDP server. See Note[3].
UDP test //Receive data from remote server
AT+CIPCLOSE // Close the UDP connection
CLOSE OK
Note [3]: For TCP, “SEND OK” means data has been sent out and received successfully by the
remote server, due to the TCP connection-oriented protocol; for UDP, “SEND OK” just
means data has been sent out from the serial port of module, not meaning data reaching
the server, due to the UDP simpler message-based connectionless protocol.
AN_SIM900_TCPIP_V1.02 2011.04.01
7