BC26 MQTT Application
Note
LPWA Module Series
Rev. BC26_MQTT_Application_Note_V1.1
Date: 2019-04-22
Status: Released
www.quectel.com
BC26 MQTT Application Note
LPWA Module Series
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. 2019. All rights reserved.
BC26_MQTT_Application_Note 1 / 24
BC26 MQTT Application Note
LPWA Module Series
About the Document
History
Revision
Date
Author
Description
1.0
2018-07-09
Louis GU
Initial
1. Optimized AT+QMTCFG command
to enable
configuration of MQTT version, sent/received data
format, and the data echo mode for data transfer.
2. Added
the maximum
length of
for
AT+QMTSUB and AT+QMTUNS.
1.1
2019-04-22
Milo WANG
3. Added the maximum length of and
for AT+QMTPUB.
4. Updated the response of all Write Commands into
“ERROR” when an error occurs, and deleted the
description of codes.
5. Updated the example in Chapter 5.
BC26_MQTT_Application_Note 2 / 24
BC26 MQTT Application Note
LPWA Module Series
Contents
About the Document ................................................................................................................................... 2
Contents ....................................................................................................................................................... 3
Table Index ................................................................................................................................................... 4
1
Introduction .......................................................................................................................................... 5
2 MQTT Data Interaction ......................................................................................................................... 6
3 MQTT Related AT Commands ............................................................................................................ 7
3.1. AT Command Syntax .................................................................................................................. 7
3.2. 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 ...................................................... 11
3.2.3. AT+QMTCLOSE Close a Network for MQTT Client ................................................... 12
3.2.4. AT+QMTCONN Connect a Client to MQTT Server ..................................................... 13
3.2.5. AT+QMTDISC Disconnect a Client from MQTT Server .............................................. 14
3.2.6. AT+QMTSUB Subscribe to Topics .............................................................................. 15
3.2.7. AT+QMTUNS Unsubscribe from Topics ...................................................................... 16
3.2.8. AT+QMTPUB Publish Messages ................................................................................ 17
4 MQTT Related URCs .......................................................................................................................... 19
4.1.
“+QMTSTAT” URC to Indicate State Change in MQTT Link Layer .......................................... 19
4.2.
“+QMTRECV” URC to Notify the Host to Read MQTT Packet Data ........................................ 20
5 Example .............................................................................................................................................. 21
6 Appendix A References ..................................................................................................................... 24
BC26_MQTT_Application_Note 3 / 24
BC26 MQTT Application Note
LPWA Module Series
Table Index
TABLE 1: MQTT RELATED URCS .................................................................................................................... 19
TABLE 2: ERROR CODES OF THE URC ......................................................................................................... 19
TABLE 3: RELATED DOCUMENTS .................................................................................................................. 24
TABLE 4: TERMS AND ABBREVIATIONS ........................................................................................................ 24
BC26_MQTT_Application_Note 4 / 24
BC26 MQTT Application Note
LPWA Module Series
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 BC26 module through AT
commands.
BC26_MQTT_Application_Note 5 / 24
BC26 MQTT Application Note
LPWA Module Series
2 MQTT Data Interaction
This chapter gives the data interaction mechanism of MQTT function.
Figure 1: MQTT Data Interaction Mechanism
BC26_MQTT_Application_Note 6 / 24
ModemMQTT ServerMCUAT+QMTCFG=“KEEPALIVE”,...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 ()Start timer T1, T2Send subscribe packetSUB ACK-IND () Receive subscribe ACK packet+QMTSUB: ,,[,]Start timer T1AT+QMTUNS=...UNS-REQ ()Send unsubscribe packetUNS ACK-IND () Receive unsubscribe ACK packet+QMTUNS: ,,Start timer T1AT+QMTPUB=...PUB-REQ ()Send publish packetPUB ACK-IND () Receive publish ACK packet+QMTPUB: ,,[,]Start timer T1AT+QMTPUB=tcpidx,topic,qos=0...PUB-REQSend publish packetStop T1 or handle Excep2Stop T1 or handle Excep2Stop T1 or handle Excep2AT+QMTPUB=...PUB-REQ ()Send publish packetPUB REC-IND ) Receive publish receive packetStart timer T1Stop T1 or handle Excep2PUB REL-REQ ()Send publish release packetStart timer T1 Receive publish complete packetStop T1 or handle Excep2PUB COMP-IND ()AT+QMTDISC=...DISC-REQSend disconnect packetAT+QMTCLOSE=... TCP-REQ TCP disconnect request...TCP disconnected+QMTCLOSE: , Receive publish packetReply according to PUB-IND ()+QMTRECV: ,,,PUB ACK/REC-REQ (msgId). . .Send publish reply packetExcep1: disconnect the TCP connection.Excep2: resend packets unless max 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, client will send pingreq packet. TCP ACKReceive PUBLISH message in the form of URC.Data report type (None URC):+QMT***: ,,…For more details, please refer to Chapter 3.AT+QMTCONNAT+QMTSUBAT+QMTUNSAT+QMTPUB(=1)AT+QMTPUB (=2)Whether the timeout information is reported can be configured by AT+QMTCFG.OKOKOKOKOKOKOKOKOKReceive+QMTDISC: ,+QMTPUB: ,,[,] BC26 MQTT Application Note
LPWA Module Series
3 MQTT Related AT Commands
This chapter presents the AT commands for operating MQTT function.
3.1. AT Command Syntax
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.
3.2. Description of MQTT Related AT Commands
3.2.1. AT+QMTCFG Configure Optional Parameters of MQTT
The command is used to configure optional parameters of MQTT.
AT+QMTCFG Configure Optional Parameters of MQTT
Test Command
AT+QMTCFG=?
Response
+QMTCFG: "echomode",(0-5),(0,1)
+QMTCFG: "dataformat",(0-5),(0,1),(0,1)
+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),"will_topic","will_ms
g"
+QMTCFG: "version",(0-5),(3,4)
BC26_MQTT_Application_Note 7 / 24