Quectel GSM TCPIP Recommended Process V2.0
Quectel GSM TCPIP Recommended Process V2.0
Recommended Process
Rev. GSM_TCP/IP_Recommended_Process_V2.0
Date: 2018-11-09
Status: Released
www.quectel.com
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
Our aim is to provide customers with timely and comprehensive service. For any
assistance, please contact our company headquarters:
GENERAL NOTES
QUECTEL OFFERS THE INFORMATION AS A SERVICE TO ITS CUSTOMERS. THE INFORMATION
PROVIDED IS BASED UPON CUSTOMERS’ REQUIREMENTS. QUECTEL MAKES EVERY EFFORT
TO ENSURE THE QUALITY OF THE INFORMATION IT MAKES AVAILABLE. QUECTEL DOES NOT
MAKE ANY WARRANTY AS TO THE INFORMATION CONTAINED HEREIN, AND DOES NOT ACCEPT
ANY LIABILITY FOR ANY INJURY, LOSS OR DAMAGE OF ANY KIND INCURRED BY USE OF OR
RELIANCE UPON THE INFORMATION. ALL INFORMATION SUPPLIED HEREIN IS SUBJECT TO
CHANGE WITHOUT PRIOR NOTICE.
COPYRIGHT
THE INFORMATION CONTAINED HERE IS PROPRIETARY TECHNICAL INFORMATION OF
QUECTEL WIRELESS SOLUTIONS CO., LTD. TRANSMITTING, REPRODUCTION, DISSEMINATION
AND EDITING OF THIS DOCUMENT AS WELL AS UTILIZATION OF THE CONTENT ARE
FORBIDDEN WITHOUT PERMISSION. OFFENDERS WILL BE HELD LIABLE FOR PAYMENT OF
DAMAGES. ALL RIGHTS ARE RESERVED IN THE EVENT OF A PATENT GRANT OR
REGISTRATION OF A UTILITY MODEL OR DESIGN.
Copyright © Quectel Wireless Solutions Co., Ltd. 2018. All rights reserved.
GSM_TCP/IP_Recommended_Process 1 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
History
GSM_TCP/IP_Recommended_Process 2 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
Contents
1 Introduction .......................................................................................................................................... 5
2 Initialization .......................................................................................................................................... 6
4 Send Data............................................................................................................................................ 10
4.1. Send Data in Unfixed Length .................................................................................................... 10
4.2. Send Data in Fixed Length ....................................................................................................... 11
10 Appendix A References..................................................................................................................... 20
GSM_TCP/IP_Recommended_Process 3 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
Table Index
GSM_TCP/IP_Recommended_Process 4 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
1 Introduction
This document introduces the simple process on how to use the embedded TCP/IP services and gives
some recommendations for handling the abnormalities.
GSM_TCP/IP_Recommended_Process 5 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
2 Initialization
AT+IPR=115200&W //Set fixed band rate as 115200bps.
OK
AT+CPIN? //Make sure the (U)SIM PIN is unlocked.
+CPIN: READY //This indicates the (U)SIM PIN is unlocked and ready.
OK
AT+CREG? //Make sure the network is registered on CS service successfully.
+CREG: 0,1 //This indicates the network is registered on CS service successfully.
Continue to execute command AT+CREG? if the registration fails. The
network registration status can also be queried by AT+CREG=1 when the
module boots; and then +CREG: 1 or +CREG: 5 will be reported when the
network registration status changes.
OK
AT+CGATT? //Query whether GPRS is attached to network successfully.
+CGATT: 1 //This indicates the GPRS is attached to network successfully. Continue to
execute command AT+CGATT? if the attachment fails. The GPRS
attachment can also be queried by AT+CGREG=1 when the module boots;
and then +CGREG: 1 or +CGREG: 5 will be reported when the GPRS
attachment status changes.
OK
AT+QIFGCNT=0 //Set the Context 0 as the foreground context. Since then the relevant
operation is carried out for Context 0.
OK
AT+QICSGP=1,“CMNET” //Choose GPRS mode and set APN as “CMNET”.
OK
1. Set address format of the server. By default, the module considers the server address as an IP
address. If the server address is a domain name, then execute AT+QIDNSIP=1 to change the server
address format to the domain name format.
2. Set the mode to handle the received data. Currently the module supports two modes to handle the
received TCP/IP data. One is to output all the received data through UART directly (default), and the
other is to output a notification +QIRD: instead of outputting the data at once after receiving it, then
GSM_TCP/IP_Recommended_Process 6 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
AT+QIRD needs to be executed to retrieve the data. If the second mode is used, then the following
command needs to be executed.
3. Set the display format of received data. When UART is selected to output the received data
directly, the following commands can be used to set the display format of the received data and can
be selected according to actual needs.
AT+QISHOWRA=1 //Add the address and port number of the data source at the
location of the received data head, and the detailed format
of the added information is: RECV FROM:<IP
ADDRESS>:<PORT>
OK
4. Set transparent mode. The default mode is non-transparent mode. The methods for establishing
TCP connection, sending and receiving data in this mode are introduced in Chapter 3~ Chapter 7. If
transparent mode is required to be used, then the following command needs to be executed. For the
specific application of the transparent mode, please refer to Chapter 8.
GSM_TCP/IP_Recommended_Process 7 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
1) The command format is wrong. If the formats of all the commands are right, verify whether
multiple TCP/IP sessions at the same time is disabled by command AT+QIMUX?. If it is disabled
(+QIMUX: 1 is returned for the read command), enable it by command AT+QIMUX=0.
2) The current TCP/IP connection status is not "IP INITIAL", "IP STATUS" or "IP CLOSE" (query by
command AT+QISTAT). If the current status is "TCP CONNECTING", execute command
AT+QICLOSE to close the current failed TCP connection. Otherwise, execute command
AT+QIDEACT to deactivate the current failed GPRS context.
2. ALREADY CONNECT. This means a TCP or UDP connection has been established. If new
connection is required, execute command AT+QICLOSE to close the current connection.
3. CONNECT FAIL. This means the TCP connection is failed to be established. The correct processing
method is to send command AT+QISTAT to query the current TCP connection status at first.
If the current status is "TCP CONNECTING", it is recommended to close the failed connection by
command AT+QICLOSE. In this way, GPRS is still active and there is no need to restart the
GPRS context, so the program speed can be improved.
If the current status is not "TCP CONNECTING", it is recommended to execute command
AT+QIDEACT to deactivate GPRS context because these status are usually caused by the
failure of GPRS context activation.
GSM_TCP/IP_Recommended_Process 8 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
For more details about the treatment of the response for AT+QIDEACT, please refer to Chapter
7. Theoretically the longest waiting time for this command is about 40s to 45s. Customers can
set timeout value which is less than 40s in their own application according to their needs. The
treatment method after the timeout is the same as that after receiving CONNECT FAIL.
Similarly, the module supports UDP mode too. Before using UDP mode, establish UDP connection first,
and the way is the same as that of establishing TCP connection.
GSM_TCP/IP_Recommended_Process 9 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
4 Send Data
SEND OK //The data has been sent to TCP protocol layer successfully.
AT+QISACK //Check whether the data has been sent successfully.
+QISACK: 4,4,0 //The first parameter “4” is the length of the data that has been sent. The
second parameter “4” is the length of the data that has been acknowledged.
The last parameter “0” is the length of the data that has been sent out but not
acknowledged yet. If the last parameter is 0, it indicates that all the data have
been sent successfully. This command is not meaningful in UDP mode
because UDP is connectionless in the mode, and whether the data has been
successfully sent cannot be confirmed. Therefore, in UDP mode, the
parameter in the middle of the three parameters is always 0 after executing
this command.
OK
NOTES
1. The send buffer in the underlying socket is 7300. Therefore, there is no need to wait for
acknowledgement of all data (which means the last parameter in the response of AT+QISACK is
0) before sending the next package. Given that the maximum length of one TCP package is 1448,
it is recommended to set a threshold value as 3000. If the unacknowledged data length (the last
parameter in the response of AT+QISACK) is less than 3000, continue to send the next package
by command AT+QISEND. Otherwise, stop sending data, and then query the data length by
GSM_TCP/IP_Recommended_Process 10 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
AT+QISACK every 5 seconds until the last parameter in the response of AT+QISACK is less than
3000. If the query time reaches a certain number (for example 20 times, which is equivalent to 100
seconds timeout) and the last parameter is always greater than 3000, it can be considered an
abnormality occurred in the TCP connection. In this case close the TCP connection, re-establish it,
and then continue to send all previously unacknowledged data and the data packages that need to
be sent.
2. If non-transparent mode is selected for sending hexadecimal characters, especially 0x08, 0x1A
and 0x1B, it is recommended to send data with fixed length. For detailed information, please refer
to Chapter 4.2.
SEND OK
AT+QISACK
+QISACK: 17,17,0
OK
GSM_TCP/IP_Recommended_Process 11 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
5 Receive Data
The received data from the server will be outputted through UART without any head information in the
default setting. In order to distinguish the received data from the responses of AT commands or any URC,
it is recommended to add some head information to the received data. For more details, please refer to
Chapter 2. It is better to set the display format of the received data before the TCP connection has been
established. Below is an example of the received data.
RECV FROM:220.180.239.212:8063<CR><LF> //The module receives data from the remote server
220.180.239.212:8063. The notification will not be
displayed if AT+QISHOWRA=1 is not executed in
initialization phase.
IPD36TCP:1234567890abcdefghijklmnopqrstuvwxyz
//Receive TCP data with the length of 36 bytes. The
detailed data is the 36 characters after the colon
symbol “:”. The header "IPD36TCP:" will not be
displayed if AT+QIHEAD=1 is not executed in
initialization phase. And the header "TCP” will not be
displayed if AT+QISHOWPT=1 is not executed in
initialization phase.
NOTE
In this mode, the data will be outputted immediately once is received, so it is unavoidable that the data
appears in the middle of the AT commands. In the current design, some timeout processing is carried out
to avoid the received data from separating a complete AT command or its response, but it is still
unavoidable separating the AT command and its response by the received data.
GSM_TCP/IP_Recommended_Process 12 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
In data retrieving mode, after module receives the TCP data or UDP data, it outputs an URC to inform the
client instead of outputting the data through UART immediately, and then the client can subsequently
extract the received TCP data by the command.
Data retrieving mode is not supported by default and needs to be enabled by AT+QINDI=1 before TCP
connection is established. An example when the module receives the data in this mode is shown as
below.
Suppose that the module receives the TCP data "1234567890abcdefghijklmnopqrstuvwxyz" from the
remote server.
+QIRDI: 0,1,0 //The module receives the data based on Context 0, and acts
as the client.
AT+QIRD=0,1,0,1500 //Retrieve the data from the module’s socket buffer. The
maximum length to retrieve is 1500 bytes. If the data length
in the buffer is less than 1500 bytes, retrieve all the data from
the buffer.
+QIRD: 220.180.239.212:8063,TCP,36<CR><LF>
1234567890abcdefghijklmnopqrstuvwxyz
OK
GSM_TCP/IP_Recommended_Process 13 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
Since the port resource of GPRS gateway is limited, so it will have some restrictions on these ports for the
terminals within the GPRS network. If there is no data transmission on the TCP connection for a period of
time, it will release the port to other connection to achieve a rational allocation of port resource. So the
TCP connection between the module and the server on the Internet may be disconnected by GPRS
network without any notification.
There is no clear value at present about how long the resource will be released without data transmission.
The test result in Shanghai is that the port resource will not be released within 10 minutes.
In order to avoid the TCP connection from disconnection by GPRS gateway without any notification, it is
recommended to periodically send a small data packet to the remote server through which the TCP
connection can be maintained and detected.
Example
For instance, according to the current results of our test, we set the interval for heartbeat packet sending
as 10 minutes. (However, in some areas, operators may limit the expiration time of TCP connection as
about 1 minute).
SEND OK //The data has been sent to TCP protocol layer successfully
Assuming no data needs to be sent for a long time later, it is recommended to send a heartbeat packet to
maintain the TCP connection. Before sending the heartbeat packet to maintain the TCP connection,
confirm if the current TCP connection is normal by querying whether the current package has been sent
GSM_TCP/IP_Recommended_Process 14 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
successfully. If the package is still not acknowledged two minutes later (query every 5 seconds for 24
times in total), the TCP connection may be abnormal. Execute AT+QICLOSE to close the current
connection, and then execute AT+QIOPEN to re-establish it. After the connection has been established
successfully, resent the unacknowledged data.
…… //Wait for 5 seconds, and then check if the heartbeat data has been sent
successfully.
GSM_TCP/IP_Recommended_Process 15 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
GSM_TCP/IP_Recommended_Process 16 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
8.1. Example
GSM_TCP/IP_Recommended_Process 17 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
If the module receives CLOSED or +PDP DEACT in the data mode, it means TCP connection has been
disconnected or some abnormalities have occurred. But it is also possible that these data are from the
remote server.
In this case, it is recommended to input +++ to confirm whether the UART is still in the data mode.
When +++ is inputted and OK is returned, it means the UART has switched to the command mode
successfully and the previously received CLOSED or +PDP DEACT are TCP data from server.
When +++ is inputted, just +++ is echoed (when echo mode is open) and OK is not returned, this
means the module has already entered into command mode. That is, the previously received
CLOSED or +PDP DEACT means the TCP connection has been disconnected or GPRS context has
been deactivated. In this case, the TCP connection needs to be re-established by the steps below. If
it is certain that the CLOSED and +PDP DEACT are not data sent by the remote server, then the
TCP connection can be re-established directly and there is no need to use +++ to judge the current
state.
GSM_TCP/IP_Recommended_Process 18 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
Notes:
1. Ensure that TE and TA are correctly synchronized after rebooting the module. Send 15 AT commands continuously following the constraint that
sleep 500ms after each AT command input, then fix and save bandrate configuration by AT+IPR=xxx&W after synchronized.
2. Please note that you need to wait for the final response (for example OK, CME error, CMS error) of the last AT command you entered before you
enter the next AT command. You can reboot the module if the module failed to get response in 60s.
3. Reboot the module if the module has not got response of AT+QIACT in 150s or response of AT+QICLOSE in 300 ms and AT+QIDEACT in 40s .
4. It is NOT recommended to frequently reboot the module. When the module has been continuously rebooted for 3 times due to failed AT command
execution, it can be rebooted immediately for the first time after that. If it still fails, reboot the module after 10 minutes for the second time, and reboot
after 30 minutes for the third time, one hour for the fourth time, etc.
GSM_TCP/IP_Recommended_Process 19 / 20
GSM/GPRS Module Series
GSM TCP/IP Recommended Process
10 Appendix A References
Abbreviation Description
The function to visit several servers or listen to multiple clients based on the
MUXIP
same GPRS/CSD context
GSM_TCP/IP_Recommended_Process 20 / 20