Quectel BG95BG77BG600L Series MQTT Application Note V1.1
Quectel BG95BG77BG600L Series MQTT Application Note V1.1
Quectel BG95BG77BG600L Series MQTT Application Note V1.1
Rev. BG95&BG77&BG600L_Series_MQTT_Application_Note_V1.1
Date: 2020-05-28
Status: Released
www.quectel.com
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
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 WITHOUT
PERMISSION ARE FORBIDDEN. 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. 2020. All rights reserved.
BG95&BG77&BG600L_Series_MQTT_Application_Note 1 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Revision History
BG95&BG77&BG600L_Series_MQTT_Application_Note 2 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Contents
1 Introduction .......................................................................................................................................... 5
1.1. Applicable Modules ..................................................................................................................... 5
5 Examples ............................................................................................................................................ 26
5.1. Example of MQTT Operation without SSL ............................................................................... 26
5.2. Example of MQTT Operation with SSL..................................................................................... 28
6 Appendix A References..................................................................................................................... 30
BG95&BG77&BG600L_Series_MQTT_Application_Note 3 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Table Index
BG95&BG77&BG600L_Series_MQTT_Application_Note 4 / 30
LPWA Module Series
BG95&BG77&BG600L Series 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 BG95 series, BG77 and
BG600L-M3 modules through AT commands.
BG95&BG77&BG600L_Series_MQTT_Application_Note 5 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
AT+QMTCFG=“will”,<client_idx>,<optional>
AT+QMTCFG=“timeout”,<client_idx>,<optional>
AT+QMTOPEN=<client_idx>,<host name>,<port>
TCP-REQ
OK TCP SYN T1 is packet
TCP SYN+ACK transmission
timeout.
TCP ACK
TCP established T2 is keep alive
+QMTOPEN: <client_idx>,<result>
timer.
AT+QMTCONN In the absence of a
AT+QMTCONN=<client_idx>,<clientID>,<optional> data-related
CONN-REQ
Send connect packet message during
OK Start timer
T1, T2 Receive connect ACK packet the T2 time period,
+QMTCONN: <client_idx>,<result>[,<ret_code>] CONN ACK-IND the client will send
Stop T1 or handle Excep1 PINGREQ packet.
Excep1:
AT+QMTSUB Disconnect the
AT+QMTSUB=<client_idx>,<msgID>,<optional>
SUB-REQ (<msgID>) TCP connection.
OK Start timer Send subscribe packet
T1 Excep2:
Resend packets
Receive subscribe ACK packet unless maximum
+QMTSUB: <client_idx>,<msgID>,<result>[,<value>] SUB ACK-IND (<msgID>)
retry times is
Stop T1 or handle Excep2
reached.
Retry times is set
AT+QMTUNS AT+QMTUNS=<client_idx>,<msgID>,<optional> by AT+QMTCFG.
UNS-REQ (<msgID>)
OK Start timer Send unsubscribe packet
T1
AT+QMTPUB AT+QMTPUB=<client_idx>,<msgID>,<qos>=2,<ret
(<qos>=2) ain>,<topic>
PUB-REQ (<msgID>)
OK Start timer Send publish packet
T1
AT+QMTDISC=<client_idx>
DISC-REQ
Send disconnect packet Note:
OK
+QMTDISC: <client_idx>,<result> <optional> refers to optional
parameters. For more details about
AT+QMTCLOSE=<client_idx> TCP-REQ optional parameters, please refer to
TCP disconnect request the description of corresponding AT
OK ...
TCP disconnected command in Chapter 3.2.
+QMTCLOSE: <client_idx>,<result>
BG95&BG77&BG600L_Series_MQTT_Application_Note 6 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
3.1.1. Definitions
The AT or at prefix must be added at the beginning of each command line. Entering <CR> will terminate a
command line. Commands are usually followed by a response that includes
<CR><LF><response><CR><LF>. Throughout this document, only the response <response> will be
presented, <CR><LF> are omitted intentionally.
BG95&BG77&BG600L_Series_MQTT_Application_Note 7 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
OK
Write Command Response
Query/set the MQTT protocol version If the optional parameter is omitted, query the MQTT protocol
AT+QMTCFG="version",<client_id version:
x>[,<vsn>] +QMTCFG: "version",<vsn>
OK
BG95&BG77&BG600L_Series_MQTT_Application_Note 8 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
BG95&BG77&BG600L_Series_MQTT_Application_Note 9 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
BG95&BG77&BG600L_Series_MQTT_Application_Note 10 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Parameter
<client_idx> Integer type. MQTT client identifier. Range: 0–5.
<vsn> Integer type. MQTT protocol version.
3 MQTT v3.1
4 MQTT v3.1.1
<cid> Integer type. The PDP to be used by the MQTT client. Range: 1–16. Default
value : 1.
<will_fg> Integer type. Configure the Will flag.
0 Ignore the Will flag configuration
1 Require the Will flag configuration
<will_qos> Integer type. Quality of service for message delivery.
0 At most once
1 At least once
2 Exactly once
<will_retain> Integer type. The Will retain flag is only used on PUBLISH messages.
0 When a client sends a PUBLISH message to a server, the server will not hold
on to the message after it has been delivered to the current subscribers
1 When a client sends a PUBLISH message to a server, the server should hold
on to the message after it has been delivered to the current subscribers
<will_topic> Will topic string. The maximum length is 255 bytes.
<will_message> String type. The Will message defines the content of the message that is
published to the Will topic if the client is unexpectedly disconnected. It can be a
BG95&BG77&BG600L_Series_MQTT_Application_Note 11 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
NOTES
BG95&BG77&BG600L_Series_MQTT_Application_Note 12 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
OK
Read Command Response
AT+QMTOPEN? [+QMTOPEN: <client_idx>,<host_name>,<port>]
OK
Write Command Response
AT+QMTOPEN=<client_idx>,<host_n OK
ame>,<port>
+QMTOPEN: <client_idx>,<result>
Characteristics /
Parameter
BG95&BG77&BG600L_Series_MQTT_Application_Note 13 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
OK
Write Command Response
AT+QMTCLOSE=<client_idx> OK
+QMTCLOSE: <client_idx>,<result>
Characteristics /
Parameter
This command is used when a client requests a connection to MQTT server. When a TCP/IP socket
connection is established from a client to a server, a protocol level session must be created using a
CONNECT flow.
OK
Read Command Response
AT+QMTCONN? [+QMTCONN: <client_idx>,<state>]
OK
Write Command Response
AT+QMTCONN=<client_idx>,<clientI OK
D>[,<username>[,<password>]]
BG95&BG77&BG600L_Series_MQTT_Application_Note 14 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
+QMTCONN: <client_idx>,<result>[,<ret_code>]
Characteristics /
Parameter
NOTES
1. If a client with the same Client ID is already connected to the server, the "older" client must be
disconnected by the server before completing the CONNECT flow of the new client.
2. AT+QMTCFG="aliauth" is only used for AliCloud. If it is configured, then <username> and
<password> in AT+QMTCONN can be omitted.
BG95&BG77&BG600L_Series_MQTT_Application_Note 15 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
This command is used when a client requests a disconnection from MQTT server. A DISCONNECT
message is sent from the client to the server to indicate that it is about to close its TCP/IP connection.
OK
Write Command Response
AT+QMTDISC=<client_idx> OK
+QMTDISC: <client_idx>,<result>
Characteristics /
Parameter
This command is used to subscribe to one or more topics. A SUBSCRIBE message is sent by a client to
register an interest in one or more topic names with the server. Messages published to these topics are
delivered from the server to the client as PUBLISH messages.
OK
Write Command Response
AT+QMTSUB=<client_idx>,<msgID OK
>,<topic1>,<qos1>[,<topic2>,<qos2
BG95&BG77&BG600L_Series_MQTT_Application_Note 16 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Parameter
NOTE
The <msgID> is only present in messages where the QoS bits in the fixed header indicate QoS levels 1
or 2. It must be unique amongst the set of "inflight" messages in a particular direction of communication. It
typically increases by exactly one from one message to the next, but is not required to do so.
This command is used to unsubscribe from one or more topics. An UNSUBSCRIBE message is sent by
the client to the server to unsubscribe from named topics.
BG95&BG77&BG600L_Series_MQTT_Application_Note 17 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
OK
Write Command Response
AT+QMTUNS=<client_idx>,<msgID OK
>,<topic1>[,<topic2>…]
+QMTUNS: <client_idx>,<msgID>,<result>
Parameter
This command publishes messages by a client to a server for distribution to interested subscribers. Each
PUBLISH message is associated with a topic name. If a client subscribes to one or more topics, any
message published to those topics are sent by the server to the client as a PUBLISH message.
BG95&BG77&BG600L_Series_MQTT_Application_Note 18 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
OK
Write Command Response
Publish variable-length messages >
AT+QMTPUB=<client_idx>,<msgID>, After > is responded, input the data to be sent. Tap Ctrl+Z to
<qos>,<retain>,<topic> send the data, and tap Esc to cancel the operation.
OK
+QMTPUB: <client_idx>,<msgID>,<result>[,<value>]
+QMTPUB: <client_idx>,<msgID>,<result>[,<value>]
Parameter
BG95&BG77&BG600L_Series_MQTT_Application_Note 19 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
NOTES
1. If this command is executed successfully and gets OK back, the client can continue to publish new
packets. The maximum quantity of packet to be transmitted should not be greater than that of inflight
windows (5).
2. After executing this command, the client will be ready to send data, which will be sent as payload. The
maximum length of the input data is 4096 bytes at a time and please tap Ctrl+Z to send the data.
3. PUBLISH messages can be sent either from a publisher to the server, or from the server to a
subscriber. When a server publishes messages to a subscriber, the following URC will be returned to
notify the host to read the received data that is reported by MQTT server:
+QMTRECV: <client_idx>,<msgID>,<topic>,<payload>
For more details about the URC description, please refer to Chapter 4.2.
This command publishes messages. It provides the same functions as AT+QMTPUB, except that the
format is different.
OK
Write Command Response
AT+QMTPUBEX=<client_idx>,<msgI OK
D>,<qos>,<retain>,<topic>,<msg>
+QMTPUB: <client_idx>,<msgID>,<result>[,<value>]
BG95&BG77&BG600L_Series_MQTT_Application_Note 20 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Parameter
NOTE
BG95&BG77&BG600L_Series_MQTT_Application_Note 21 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
This command reads messages from storage buffer where the messages are stored when they are
reported by the server.
OK
OK
Characteristics /
Parameter
BG95&BG77&BG600L_Series_MQTT_Application_Note 22 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
BG95&BG77&BG600L_Series_MQTT_Application_Note 23 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
The URC begins with +QMTSTAT:. It will be reported when there is a change in the state of MQTT link
layer.
Parameter
<client_idx> Integer type. MQTT client identifier. Range: 0–5.
<err_code> Integer type. An error code. Please refer to the table below for details.
BG95&BG77&BG600L_Series_MQTT_Application_Note 24 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
Sending PINGREQ packet timed out Deactivate PDP first, and then activate PDP and
2
or failed. reopen MQTT connection.
1. Check whether the inputted user name and
password are correct.
Sending CONNECT packet timed out
3 2. Make sure the client ID is not used.
or failed.
3. Reopen MQTT connection and try to send
CONNECT packet to the server again.
1. Check whether the inputted user name and
password are correct.
Receiving CONNACK packet timed
4 2. Make sure the client ID is not used.
out or failed.
3. Reopen MQTT connection and try to send
CONNECT packet to the server again.
The client sends DISCONNECT
5 packet to sever and the server is This is a normal process.
initiative to close MQTT connection.
The client takes the initiative to close 1. Make sure the data is correct.
6 the MQTT connection due to packet 2. Try to reopen MQTT connection since there
sending failure all the time. may be network congestion or an error.
The link is not alive or the server is Make sure the link is alive or the server is
7
unavailable. available currently.
8–255 Reserved for future use.
4.2. +QMTRECV: URC to Inform the Host to Read MQTT Packet Data
The URC begins with +QMTRECV:. It is mainly used to inform the host to read the received MQTT packet
data that is reported from MQTT server.
Parameter
<client_idx> Integer type. MQTT client identifier. Range: 0–5.
<msgID> Integer type. The message identifier of packet.
<topic> String type. The topic that received from MQTT server.
<payload> String type. The payload that relates to the topic name.
<recv_id> Integer type. The serial number of every single message received. Range: 0–4.
BG95&BG77&BG600L_Series_MQTT_Application_Note 25 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
5 Examples
This chapter gives some examples to explain how to use MQTT related AT commands.
AT+QMTCFG="aliauth",0,"oyjtmPl5a5j","MQTT_TEST","wN9Y6pZSIIy7Exa5qVzcmigEGO4kAazZ"
//Configure Alibaba device information for AliCloud.
OK
AT+QMTOPEN=?
+QMTOPEN: (0-5),<host_name>,(0-65535)
OK
AT+QMTOPEN=0,"iot-as-mqtt.cn-shanghai.aliyuncs.com",1883 //Open a network for MQTT client.
OK
OK
AT+QMTCONN=?
+QMTCONN: (0-5),<clientID>,<username>,<password>
OK
OK
BG95&BG77&BG600L_Series_MQTT_Application_Note 26 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
//Subscribe to topics.
AT+QMTSUB=0,1,"topic/example",2
OK
+QMTSUB: 0,1,0,2
AT+QMTSUB=0,1,"topic/pub",0
OK
+QMTSUB: 0,1,0,0
//If a client subscribes to a topic and other devices publish the same topic to the server, the module will
report the following information.
+QMTRECV: 0,0,"topic/example","This is the payload related to topic"
+QMTUNS: 0,2,0
AT+QMTPUB=?
+QMTPUB : (0-5),(0-65535),(0-2),(0,1),<topic>,(1-4096)
OK
//Publish messages.
AT+QMTPUB=0,0,0,0,"topic/pub"
>This is test data, hello MQTT. //After receiving >, input data This is test data, hello MQTT. and
then send it. The maximum length of the data is 4096 bytes and the
data that beyond 4096 bytes will be omitted. After inputting data,
tap Ctrl+Z to send.
OK
+QMTPUB: 0,0,0
//If a client subscribes to a topic named "topic/pub" and other devices publish the same topic to the server,
the module will report the following information.
+QMTRECV: 0,0,"topic/pub","This is test data, hello MQTT."
AT+QMTDISC=0 //Disconnect a client from MQTT server.
OK
BG95&BG77&BG600L_Series_MQTT_Application_Note 27 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
//If SSL authentication mode is intended to be set as "manage server and client authentication if
requested by the remote server" (<seclevel>=2 in AT+QSSLCFG), upload server root CA certificate,
client certificate and client private key to UFS.
AT+QFUPL="cacert.pem",1758,100 //Upload CA certificate to UFS.
CONNECT
<Input the cacert.pem data, and the size is 1758 bytes>
+QFUPL: 1758,384a
OK
OK
AT+QFUPL="user_key.pem",1679,100 //Upload client private key to UFS.
CONNECT
<Input the user_key.pem data, and the size is 1679 bytes>
+QFUPL: 1679,335f
OK
BG95&BG77&BG600L_Series_MQTT_Application_Note 28 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
+QMTOPEN: 0,0
+QMTCONN: 0,0,0
//Subscribe to topics.
AT+QMTSUB=0,1,"$aws/things/ MQTT-1/shadow/update/accepted",1
OK
+QMTSUB: 0,1,0,1
//Publish messages.
AT+QMTPUB=0,1,1,0,"$aws/things/MQTT-1/shadow/update/accepted"
>This is publish data from client
OK
+QMTPUB: 0,1,0
+QMTDISC: 0,0
BG95&BG77&BG600L_Series_MQTT_Application_Note 29 / 30
LPWA Module Series
BG95&BG77&BG600L Series MQTT Application Note
6 Appendix A References
[1] MQTT V3.1 Protocol Specification MQTT protocol specification version 3.1
[2] MQTT V3.1.1 Protocol Specification MQTT protocol specification version 3.1.1
Abbreviation Description
ACK Acknowledgement
CA Certificate Authority
BG95&BG77&BG600L_Series_MQTT_Application_Note 30 / 30