sim900a TCP 应用(1)

2020-03-01 159浏览

  • 1.SIM900_TCPIP_Application Note_V1.02 AN_SIM900_TCPIP_V1.02 1 2011.04.01
  • 2.Smart Machine Smart Decision DocumentTitle:TCPIP Application NoteVersion:1.02Date:2011-4-1Status:Release Document ControlID:AN_SIM900_TCPIP_Application Note_V1.02 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
  • 3.Smart Machine Smart Decision Contents Version history..................................................................................................................................3 1 Structure ....................................................................................................................................4 2 Single Connection .....................................................................................................................5 2.1 Non-transparent mode...................................................................................................5 2.1.1 How to Establish a TCP Client Connection ......................................................5 2.1.2 How to Establish a UDP Client Connection......................................................7 2.1.3 How to Establish a TCP Server Connection......................................................8 2.1.4 UDP Extended Mode ........................................................................................9 2.2 Transparent Mode .......................................................................................................11 2.2.1 What is Transparent Mode ..............................................................................11 2.2.2 How to Configure Transparent Mode..............................................................11 2.2.3 How to Establish Connection under Transparent Mode..................................11 2.2.4 How to Switch Between Data Mode and Command Mode.............................12 2.2.5 How to handle incoming call and short message in data mode.......................13 2.3 Fix Local Port of TCP/UDP Client .............................................................................13 3 Multi Connection ....................................................................................................................14 3.1 As a Client...................................................................................................................14 3.2 As a TCP Server..........................................................................................................16 4 DNS Function .........................................................................................................................19 5 Data Sending Related..............................................................................................................20 5.1 Fixed Length Sending .................................................................................................20 5.2 Timed Sending ............................................................................................................20 5.3 Query Available Data Length to be Sent .....................................................................20 5.4 Select Data Transmitting Mode...................................................................................21 5.5 Query Data Transmitting Amount ...............................................................................21 6 Data Receiving Related...........................................................................................................23 6.1 Receive Data Automatically........................................................................................23 6.2 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 AN_SIM900_TCPIP_V1.02 2 2011.04.01
  • 4.Smart Machine Smart Decision Version history Date Version Description of change 2010-6-22 1.01 Added “UDP Extended Mode” 2011-4-1 1.02 Added CIPRXGET application in chapter 6.2 Author Chenyang 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 3 2011.04.01
  • 5.Smart Machine Smart Decision 1 Structure There are two modes of connection for SIM900 TCP/IPapplication: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 4 2011.04.01
  • 6.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 thismode: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+CSQCSQ: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 5 2011.04.01
  • 7.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 6 2011.04.01
  • 8.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 7 2011.04.01
  • 9.Smart Machine Smart Decision 2.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. Userr should use the command “AT+CIPSERVER=1,”” to start the server function and set listening port. If it is successful, response “SERVER OK” will be returned, and now the server starts to listen to the TCP port. And then, user should use command “AT+CIFSR” to get local IP address, which is the server IP address. 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 user can use command AT+CIPSEND to send data to remote client. User can use “AT+CIPSERVER=0” to close the listening status. Also, user can use AT+CIPCLOSE to close the TCP connection. AT+CGATT? +CGATT:1 OK AT+CIPSERVER=1,1234 //Start the TCP server, listeningport:1234OK SERVER OK //TCP server is established successfully AT+CIFSR //Get local IP address 10.78.33.227 AT+CIPSTATUS OKSTATE:SERVER LISTENING // Query currentstatus:listening REMOTEIP: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 AN_SIM900_TCPIP_V1.02 //Just close the listening status, the current 8 2011.04.01
  • 10.Smart Machine Smart Decision connection is still active. OK SERVER CLOSE hello sim900 //Receive data from remote client AT+CIPCLOSE //Close the TCP connection CLOSE OK 2.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",8888 //Set 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 AN_SIM900_TCPIP_V1.02 //Enable the UDP Extended Mode 9 2011.04.01
  • 11.Smart Machine Smart Decision OK AT+CIPSTART="UDP","116.228.221.51",9600 // Start up UDP connection to remote server OK CONNECT OK AT+CIPUDPMODE? +CIPUDPMODE:'>CIPUDPMODE: