TCPIP Application Note
AN_SIM900_TCPIP_V1.01
Document Title: Version: Date: Status:
Document Control ID:
TCPIP Application Note 1.01 2010-6-22 Update
AN_SIM900_TCPIP_Application Note_V1.01
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. 2004
SIM900 TCPIP Application Note
Contents
Version history..................................................................................................................................3 1. Introduction...................................................................................................................................4
1.1 Scope of the document.........................................................................................................4 1.2 Related documents...............................................................................................................4 1.3 Conventions and abbreviations............................................................................................4 2. Structure........................................................................................................................................5 3. Single Connection.........................................................................................................................6
3.1 Non-transparent mode..........................................................................................................6
3.1.1 How to establish a TCP client connection..................................................................6 3.1.2 How to establish a UDP client connection.................................................................8 3.1.3 How to establish a TCP server connection.................................................................9 3.1.4 UDP Extended Mode................................................................................................10 3.2 Transparent mode...............................................................................................................12
3.2.1 What is transparent mode.........................................................................................12 3.2.2 How to configure transparent mode.........................................................................12 3.2.3 How to establish connection under transparent mode..............................................12 3.2.4 How to switch between data mode and command mode..........................................13 3.2.4 How to handle incoming call and short message in data mode................................14 3.3 Fix local port of TCP/UDP client.......................................................................................14 4. Multi Connection........................................................................................................................14
4.1 As a client...........................................................................................................................14 4.2 As a TCP server.................................................................................................................16 5. DNS function..............................................................................................................................19 6. Data sending related....................................................................................................................19
6.1 Fixed length sending..........................................................................................................20 6.2 Timed sending....................................................................................................................20 6.3 Query available data length to be sent................................................................................20 6.4 Select data transmitting mode............................................................................................20 6.5 Query data transmitting amount.........................................................................................21 7. Data receiving related.................................................................................................................22 8. gprs states exchange related........................................................................................................23 9. Connection closing related..........................................................................................................25 10. Connection activity checking related........................................................................................25 11. Power consumption with existing connection...........................................................................25 12. Error handling...........................................................................................................................26
2AN_SIM900_TCPIP_V1.01 22.06.2010
SIM900 TCPIP Application Note
VERSION HISTORY
Now document: SIM900 TCPIP Application Note” Version 1.01 Chapter Page V1.01
What is new
Add “UDP Extended Mode”
3AN_SIM900_TCPIP_V1.01 22.06.2010
SIM900 TCPIP Application Note
1. INTRODUCTION
1.1 Scope of the document
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.
1.2 Related documents
[1] SIM900 AT Commands Set.
1.3 Conventions and abbreviations
TCP Transmission Control Protocol UDP User Datagram Protocol APN Access Point Name GPRS General Packet Radio Service PDP Packet Data Protocol DNS Domain Name System
AN_SIM900_TCPIP_V1.01 22.06.20104
SIM900 TCPIP Application Note
2. 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 only can 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 also can be configured as one TCP server, which allows 7 TCP/UDP clients to connect in; 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
5AN_SIM900_TCPIP_V1.01 22.06.2010
SIM900 TCPIP Application Note
3. SINGLE CONNECTION
Command AT+CIPMUX= 3.1 Non-transparent mode Command AT+CIPMODE= 3.1.1 How to establish a TCP client connection Firstly, before any TCP/UDP related operation, the module should be connected to GSM or GPRS network. You 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, you should use the command group AT+CSTT, AT+CIICR and AT+CIFSR to start the task and activate the wireless connection. Lastly, you can establish TCP connection between SIM900 and server by AT command (AT+CIPSTART=”TCP”,”IP Address of server”, “port 6AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note number of server”). If the connection is established successfully, response “CONNECT OK” will come up from the module. Now you can send data to server with “AT+CIPSEND”. “AT+CIPSEND” will return with promoting mark “>”, you 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 server, the module will receive the data automatically from the serial port. You 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 // The remote server receives the 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. Please ask your local GSM provider to get the APN. //附着和分离GPRS业务7AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note Note[2]: You should write data only after the promoting mark “>” ,and then use CTRL+Z to send. You can use command “AT+CIPSPRT” to set whether echo promote “>” after issuing “AT+CIPSEND”. 3.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 // The 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 the 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 the data has been sent out from the serial port of module, not meaning the data reaching the server, due to the UDP simpler message-based connectionless protocol. 8AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 3.1.3 How to establish a TCP server connection In single connection mode, when configured as TCP server, SIM900 allows one client to connect in. You should use the command “AT+CIPSERVER=1,” If the client connects to the server successfully, the IP address of remote client will be displayed at server side. And the server can receive TCP data from remote side. Also you can use command AT+CIPSEND to send data to remote client. You can use “AT+CIPSERVER=0” to close the listening status. Also, you can use AT+CIPCLOSE to close the TCP connection. AT+CGATT? +CGATT: 1 OK AT+CIPSERVER=1,1234 //Start the TCP server, listening port:1234 OK SERVER OK //TCP server is established successfully AT+CIFSR //Get local IP address 10.78.33.227 AT+CIPSTATUS OK STATE: SERVER LISTENING // Query current status: listening REMOTE IP: 10.78.103.220 // Remote client connected in hello server // Receive data from remote client AT+CIPSNED >hello client // Send data to remote client SEND OK AT+CIPSERVER=0 //Just close the listening status, the current 9AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note connection is still active. OK SERVER CLOSE hello sim900 //Receive data from remote client AT+CIPCLOSE //Close the TCP connection CLOSE OK 3.1.4 UDP Extended Mode In UDP extended mode, SIM900 can receive UDP data from any IP address and port, meanwhile it can send UDP data to any IP address and port. AT+CGATT? +CGATT: 1 OK AT+CSTT OK AT+CIICR OK AT+CIFSR 10.92.17.107 AT+CLPORT=\"UDP\local UDP port OK AT+CIPSRIP=1 //Display IP address and Port of sender OK AT+CIPHEAD=1 //Add IP head in receiving data OK AT+CIPUDPMODE=1 //Enable the UDP Extended Mode 10AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note OK AT+CIPSTART=\"UDP\ // Start up UDP connection to remote server OK CONNECT OK AT+CIPUDPMODE? +CIPUDPMODE: 1,\"116.228.221.51\ OK RECV FROM: 116.228.221.51:9600 // Receiving data from different IP address and port. +IPD,5:test1 RECV FROM: 116.228.221.51:1234 +IPD,5:test2 RECV FROM: 10.78.103.220: 5678 +IPD,5:test3 AT+CIPSEND //Send data to server defined by “AT+CIPSTART” > Hello 9600 SEND OK AT+CIPUDPMODE=2,\"211.136.131.65\ //Re-set UDP address to be sent data to. OK AT+CIPUDPMODE? +CIPUDPMODE: 1,\"211.136.131.65\ //The destination UDP address has been updated, and UDP extended mode is still on OK AT+CIPSEND // Send data to updated UDP address > Hello 4500 SEND OK 11AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 3.2 Transparent mode 3.2.1 What is transparent mode SIM900 supports transparent mode which provides a special data mode for data receiving and sending by TCP/IP application task. Once the connection is established under transparent mode, the module will be in data mode. All received data from serial port will be treated as data packet to be transferred later, similarly all data received from remote side will be sent to serial port directly. In transparent mode, all AT commands are not available. Methods are provided to switch back and forth between data mode and command mode. Once switched to command mode, all AT commands can be used again. Note:The flow control is default off. It is better to open the hardware flow control for using transparent mode, by setting AT+IFC=2,2. 3.2.2 How to configure transparent mode To enable transparent mode, the command AT+CIPMODE should be set to 1. In transparent mode, the command AT+CIPCCFG is used for configuring transfer mode, which has 4 parameters NmRetry, WaitTm, SendSz, Esc. NmRetry is the number of retries to be made for an IP packet. WaitTm is the number of 200ms intervals to wait for incoming data before sending the packet. SendSz is the size of data block to be received from serial port before sending. Esc represents whether the escape sequence is allowed, default is TRUE. 3.2.3 How to establish connection under transparent mode The transparent mode is only supported under single connection. In transparent mode, SIM900 can work as three modes too: TCP client, UDP client and TCP server. Once the connection is established, CONNECT will be returned in the serial port and the module will be in data mode. At the same time, DCD pin will be active low. Below is an example of TCP client connection. AT+CIPMODE=1 //Enable transparent mode OK AT+CGATT? +CGATT: 1 OK AT+CSTT=”CMNET” OK AT+CIICR OK 12AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note AT+CIFSR 10.76.157.180 AT+CIPSTART=”TCP”,”116.228.221.51”,”8500” OK CONNECT //Connected sucessfully, enter into data mode .................. //Input data to serial port OK //Quit data mode by pulling DTR or using “+++” ATO //Return to data mode CONNECT sim900 channel test //Data received from remote server CLOSED //Closed by remote server, quit data mode 3.2.4 How to switch between data mode and command mode To switch from data mode to command mode, following methods are available: (1) The escape sequence can be used if the last parameter of AT+CIPCCFG is TRUE. The default escape sequence is +++, and to use this sequence, there should be 1000ms idle period before this sequence and 500ms idle period after this sequence. Besides, the interval between each + should not exceed 500ms, otherwise it will be treated as TCP/IP data. (2) DTR line of serial port can also be used. To use this method, AT&D1 should be set firstly. Pull DTR line to ground for at least 1 second and then pull up, the module will switch from data mode to command mode and OK will be returned indicating the module is in command mode. (3) For TCP client connection, if the remote server closes the connection, the module will switch back to command mode automatically. (4) For TCP server connection, if the remote client closes the connection, the module will switch back to command mode automatically. (5) If the module is deactivated from PDP context (+PDP DEACT) during data transferring, module will switch back to command mode automatically. ATO command can be used to switch from command mode to data mode if the connection is active, and CONNECT will be returned again. 13AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 3.2.4 How to handle incoming call and short message in data mode RI pin of serial port will give a 50ms low pulse when a call is coming during data mode. RI pin will give a 120ms low pulse when a short message is received. To handle the incoming call or SMS, you need to enter command mode first (using DTR or +++), and then the module will give the normal unsolicited responses as following: RING //incoming call +CMTI: “SM”, 10 //short message And then it is able to answer the call or read the short message. 3.3 Fix local port of TCP/UDP client Normally, if client SIM900 establishes TCP/UDP connection to remote server, the TCP/UDP connection will be dynamically allocated a local port when AT+CLPORT is set to 0. If AT+CLPORT is set to a nonzero value, the local port will be fixed at this value. The default configuration of this command is 0. Be aware that this command will be effective only in single connection and when module as a client. 4. MULTI CONNECTION To enable multi connection, the command AT+CIPMUX must be set to 1. Be aware that in the multi connection, SIM900 only supports non-transparent mode. Due to this matter, the command AT+CIPMODE is invalid under multi connection. In multi connection, SIM900 can work as a TCP/UDP client or a TCP server. As a client, it can establish 8 connections to remote server in total, both TCP and UDP. As a TCP server, it allows remote clients to connect in; at the same time, it can establish TCP/UDP connections to upper remote servers. Total 7 available connections are supported, with the server itself occupying one connection. 4.1 As a client Being a client, SIM900 can establish both TCP and UDP connection to remote server. Total 8 connections are supported. The command “AT+CIPSTART= returned. And then you can use command AT+CIPSNED= 14AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note close one specific connection with number AT+CIPMUX=1 //Enable multi connection OK AT+CGATT? +CGATT: 1 OK AT+CSTT=”CMNET” OK AT+CIICR OK AT+CIFSR 10.76.166.72 AT+CIPSTART=0,”TCP”,”116.228.221.51”,”8500” //Establish a TCP connection, connection number 0 OK 0, CONNECT OK AT+CIPSTART=1,”UDP”,”116.228.221.51”,”9600” //Establish a UDP connection, connection number 1 OK 1, CONNECT OK AT+CIPSEND=0 //Send data to connection 0 > TCP test 0, SEND OK AT+CIPSEND=1 //Send data to connection 1 >UDP test 1, SEND OK 15AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note +RECEIVE,0,17: //Received data from connection 0, data length 17 sim900 TCP test +RECEIVE,1,17 //Received data from connection 1, data length 17 sim900 UDP test 1, CLOSED //Connection 1 is closed by remote server AT+CIPSTATUS //Query the current connection status OK STATE: IP PROCESSING C: 0,0,\"TCP\ C: 1,0,\"UDP\ C: 2,,\"\C: 3,,\"\C: 4,,\"\C: 5,,\"\C: 6,,\"\C: 7,,\"\ 4.2 As a TCP server Being a TCP server, SIM900 allows remote clients to connect in; in the meanwhile, it can establish TCP/UDP connections to remote servers too. Before launching the server function, command group “AT+CSTT, AT+CIICR, AT+CIFSR” should be executed to activate the PDP context and get local IP address. Then you can send command “AT+CIPSERVER=1, If the clients connect to the server successfully, the IP addresses of remote clients together with connection numbers “AT+CIPSERVER=0” can be used to close the listening status. You can use command AT+CIPCLOSE= AT+CIPMUX=1 OK 16AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note AT+CGATT? +CGATT: 1 OK AT+CSTT=”CMNET” OK AT+CIICR OK AT+CIFSR 10.76.40.73 AT+CIPSERVER=1,8888 //Start server;listeninig port:8888 OK SERVER OK 0, REMOTE IP: 10.76.40.73 //Remote client connect in, connection number 0 allocated +RECEIVE,0,39: //Received data from remote client, data length 39 sim900 multi connection TCP server test AT+CIPSEND=0 //Send data to remote client > hello client 0, SEND OK AT+CIPSTART=1,”TCP”,”116.228.221.51”,”8500” //Establish TCP connection to remote server OK 1, CONNECT OK AT+CIPSTART=2,”UDP”,”116.228.221.51”,”9600” //Establish UDP connection to remote server OK 17AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 2, CONNECT OK AT+CIPSEND=1 // Send TCP data to remote server > data from connection 1 1, SEND OK 1, data to connection 1 //Received TCP data from remote server AT+CIPCLOSE=2 //Close the UDP connection with remote server 2, CLOSE OK AT+CIPSTATUS //Query current connection status OK STATE: IP PROCESSING S: 0,0,\"8888\ //The TCP server is in the process of listening, occupying one connection C: 0,0,\"TCP\C: 1,0,\"TCP\C: 2,0,\"UDP\C: 3,,\"\C: 4,,\"\C: 5,,\"\C: 6,,\"\C: 7,,\"\ AT+CIPSERVER=0 //Close the server OK SERVER CLOSE AT+CIPSHUT //Deactivate the PDP context &close all connections SHUT OK 18AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 5. DNS FUNCTION SIM900 supports DNS auto parsing, so you can establish TCP/UDP connection to remote sever using domain name directly by the command “AT+CIPSTART= You also can use command AT+CDNSGIP= AT+CDNSGIP=\"WWW.SIM.COM\" OK +CDNSGIP: 1,\"WWW.SIM.COM\ WWW.SIM.COM” is “58.32.231.146” AT+CDNSGIP=\"abctest\" OK +CDNSGIP: 0,11 //Parsing fails, reason is 11 AT+CIPSTART=\"TCP\ domain name OK CONNECT OK AT+CIPSNED > DNS test SEND OK 6. DATA SENDING RELATED SIM900 provides three ways to send data: changeable data length sending, fixed data length sending and timed sending. SIM900 also provides a method to let you know how much data is sent out from the module and received by remote server on an active TCP connection. 19AN_SIM900_TCPIP_V1.01 22.06.2010 SIM900 TCPIP Application Note 6.1 Fixed length sending You can send the fixed length of data with “AT+CIPSEND= 6.2 Timed sending There is another way to send data automatically. First, set the timer of sending data automatically by the command “AT+CIPATS=
Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务