logo资料库

Quectel_EC2x&EG9x;&EM05;_MQTT_Application_Note_V1.1.pdf

第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
资料共31页,剩余部分请下载后查看
About the Document
Contents
Table Index
1 Introduction
2 MQTT Data Interaction
3 MQTT Related AT Commands
3.1. AT Command Syntax
3.2. Description of MQTT Related AT Commands
3.2.1. AT+QMTCFG Configure Optional Parameters of MQTT
3.2.2. AT+QMTOPEN Open a Network for MQTT Client
3.2.3. AT+QMTCLOSE Close a Network for MQTT Client
3.2.4. AT+QMTCONN Connect a Client to MQTT Server
3.2.5. AT+QMTDISC Disconnect a Client from MQTT Server
3.2.6. AT+QMTSUB Subscribe to Topics
3.2.7. AT+QMTUNS Unsubscribe from Topics
3.2.8. AT+QMTPUBEX Publish Messages
3.2.9. AT+QMTRECV Read Messages from Buffers
4 MQTT Related URCs
4.1. “+QMTSTAT” URC to Indicate State Change in MQTT Link Layer
4.2. “+QMTRECV” URC to Notify the Host to Read MQTT Packet Data
4.3. “+QMTPING” URC to Indicate PING State of Keep-alive in MQTT
5 Examples
5.1. Example of MQTT Operation without SSL
5.2. Example of MQTT Operation with SSL
6 Appendix A References
EC2x&EG9x&EM05 MQTT Application Note LTE Module Series Rev. EC2x&EG9x&EM05_MQTT_Application_Note_V1.1 Date: 2018-12-12 Status: Released www.quectel.com
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note Our aim is to provide customers with timely and comprehensive service. For any assistance, please contact our company headquarters: Quectel Wireless Solutions Co., Ltd. 7th Floor, Hongye Building, No.1801 Hongmei Road, Xuhui District, Shanghai 200233, China Tel: +86 21 5108 6236 Email: info@quectel.com Or our local office. For more information, please visit: http://www.quectel.com/support/sales.htm For technical support, or to report documentation errors, please visit: http://www.quectel.com/support/technical.htm Or email to: support@quectel.com 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. EC2x&EG9x&EM05_MQTT_Application_Note 1 / 30
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note About the Document History Revision Date Author Description 1.0 1.1 2018-08-21 Chavis CHEN Initial 2018-12-12 Slark WANG Added Write Command AT+QMTCFG=“qmtping” and its related information EC2x&EG9x&EM05_MQTT_Application_Note 2 / 30
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note Contents About the Document ................................................................................................................................... 2 Contents ....................................................................................................................................................... 3 Table Index ................................................................................................................................................... 4 1 Introduction .......................................................................................................................................... 5 2 MQTT Data Interaction ......................................................................................................................... 6 3.1. 3.2. 3 MQTT Related AT Commands ............................................................................................................ 7 AT Command Syntax ............................................................................................................... 7 Description of MQTT Related AT Commands ......................................................................... 7 3.2.1. AT+QMTCFG Configure Optional Parameters of MQTT .............................................. 7 3.2.2. AT+QMTOPEN Open a Network for MQTT Client ...................................................... 13 3.2.3. AT+QMTCLOSE Close a Network for MQTT Client ................................................... 14 3.2.4. AT+QMTCONN Connect a Client to MQTT Server ..................................................... 14 3.2.5. AT+QMTDISC Disconnect a Client from MQTT Server .............................................. 16 3.2.6. AT+QMTSUB Subscribe to Topics .............................................................................. 16 3.2.7. AT+QMTUNS Unsubscribe from Topics ...................................................................... 17 3.2.8. AT+QMTPUBEX Publish Messages ........................................................................... 18 3.2.9. AT+QMTRECV Read Messages from Buffers ............................................................ 20 4 MQTT Related URCs .......................................................................................................................... 22 “+QMTSTAT” URC to Indicate State Change in MQTT Link Layer ...................................... 22 “+QMTRECV” URC to Notify the Host to Read MQTT Packet Data .................................... 24 “+QMTPING” URC to Indicate PING State of Keep-alive in MQTT ...................................... 24 4.1. 4.2. 4.3. 5 Examples ............................................................................................................................................ 25 Example of MQTT Operation without SSL ............................................................................ 25 Example of MQTT Operation with SSL ................................................................................. 27 5.1. 5.2. 6 Appendix A References ..................................................................................................................... 30 EC2x&EG9x&EM05_MQTT_Application_Note 3 / 30
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note Table Index TABLE 1: TYPES OF AT COMMANDS AND RESPONSES ............................................................................... 7 TABLE 2: MQTT RELATED URCS .................................................................................................................... 22 TABLE 3: ERROR CODES OF THE URC ......................................................................................................... 23 TABLE 4: RELATED DOCUMENTS .................................................................................................................. 30 TABLE 5: TERMS AND ABBREVIATIONS ........................................................................................................ 30 EC2x&EG9x&EM05_MQTT_Application_Note 4 / 30
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note 1 Introduction MQTT (Message Queuing Telemetry Transport) is a broker-based publish/subscribe messaging protocol designed to be open, simple, lightweight and easy to implement. It is designed for connections with remote locations where a “small code footprint” is required or the network bandwidth is limited. This document mainly introduces how to use the MQTT function of Quectel EC2x&EG9x&EM05 modules through AT commands. This document is applicable to following Quectel modules.  EC2x (including EC25, EC21, EC20 R2.0 and EC20 R2.1)  EG9x (including EG91 and EG95)  EM05 EC2x&EG9x&EM05_MQTT_Application_Note 5 / 30
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note 2 MQTT Data Interaction This chapter gives the data interaction mechanism of MQTT function. Figure 1: MQTT Data Interaction Diagram EC2x&EG9x&EM05_MQTT_Application_Note 6 / 30 ModemMQTT ServerMCUAT+QMTCFG=“will”,,AT+QMTCFG=“timeout”,,AT+QMTOPEN=,“”,Link layer TCP-REQ TCP SYN TCP SYN+ACKTCP established+QMTOPEN: ,AT+QMTCONN=,“”,CONN-REQSend connect packet Receive connect ACK packetCONN ACK-IND+QMTCONN: ,[,]Stop T1 or handle Excep1AT+QMTSUB=,...SUB-REQ (msgId)Start timer T1, T2Send subscribe packetSUB ACK-IND (msgId) Receive subscribe ACK packet+QMTSUB:,,[,]Start timer T1AT+QMTUNS=,...UNS-REQ (msgId)Send unsubscribe packetUNS ACK-IND (msgId) Receive unsubscribe ACK packet+QMTUNS: ,,Start timer T1AT+QMTPUB=,,=1,,“”PUB-REQ (msgId)Send publish packetPUB ACK-IND (msgId) Receive publish ACK packet+QMTPUB: ,,[,]Start timer T1AT+QMTPUB=,,=0,,“”PUB-REQSend publish packetStop T1 or handle Excep2Stop T1 or handle Excep2Stop T1 or handle Excep2AT+QMTPUB=,,=2,,“”PUB-REQ (msgId)Send publish packetPUB REC-IND (msgId) Receive publish receive packetStart timer T1Stop T1 or handle Excep2PUB REL-REQ (msgId)Send publish release packetStart timer T1 Receive publish complete packetStop T1 or handle Excep2PUB COMP-IND (msgId)+QMTPUB: ,,[,]AT+QMTDISC=DISC-REQSend disconnect packetAT+QMTCLOSE= TCP-REQ TCP disconnect request...TCP disconnected+QMTCLOSE: , Receive publish packetReply according to PUB-IND (msgId)+QMTRECV: ,,,PUB ACK/REC-REQ (msgId)...Send publish reply packetExcep1: Disconnect the TCP connection.Excep2: Resend packets unless maximum retry times is reached.Retry times is set by AT+QMTCFG.T1 is packet transmission timeout.T2 is keep alive timer.In the absence of a data-related message during the T2 time period, the client will send PINGREQ packet. TCP ACKReceive PUBLISH message in the form of URC.Data report type (None URC):+QMT***: ,,…(1) =0: Receive ACK packets from server;(2) =1: Packet sending timeout and retransmission;(3) =2: Packet sending timeout and the maximum times of transmission is reached.+QMTSUB: tcpidx,1,msgId+QMTUNS: tcpidx,1,msgId+QMTPUB: tcpidx,1,msgId+QMTPUB: tcpidx,1,msgId+QMTPUBREL: tcpidx,1,msgIdAT+QMTCONNAT+QMTSUBAT+QMTUNSAT+QMTPUB(=1)AT+QMTPUB (=2)Whether the timeout information is reported can be configured by AT+QMTCFG.OKOKOKOKOKOKOKOKOKReceive+QMTDISC: ,Note: refers to optional parameters. For more details about optional parameters, please refer to the description of corresponding AT command in Chapter 3.2.
LTE Module Series EC2x&EG9x&EM05 MQTT Application Note 3 MQTT Related AT Commands This chapter presents the AT commands for operating MQTT function. Table 1: Types of AT Commands and Responses Test Command AT+=? Read Command AT+? This command returns the list of parameters and value ranges set by the corresponding Write Command or internal processes. This command returns the currently set value of the parameter or parameters. Write Command AT+=<…> This command sets the user-definable parameter values. Execution Command AT+ This command reads non-variable parameters affected by internal processes in the UE. The command is used to configure optional parameters of MQTT. AT+QMTCFG Configure Optional Parameters of MQTT Test Command AT+QMTCFG=? Response +QMTCFG: “version”,(0-5),(3,4) +QMTCFG: “pdpcid”,(0-5),(1-16) +QMTCFG: “ssl”,(0-5),(0,1),(0-5) +QMTCFG: “keepalive”,(0-5),(0-3600) +QMTCFG: “session”,(0-5),(0,1) +QMTCFG: “timeout”,(0-5),(1-60),(1-10),(0,1) +QMTCFG: “will”,(0-5),(0,1),(0-2),(0,1),“willtopic”,“willmess age” EC2x&EG9x&EM05_MQTT_Application_Note 7 / 30
分享到:
收藏