SIM800 Series_MQTT
_Application Note
GPRS Module
SIMCom Wireless Solutions Limited
Building B, SIM Technology Building, No.633, Jinzhong Road
Changning District, Shanghai P.R. China
Tel: 86-21-31575100
support@simcom.com
www.simcom.com
SIM800 Series_MQTT_Application Note_V1.03
Document Title:
Version:
Date:
Status:
GENERAL NOTES
SIM800 Series _MQTT_Application Note
1.03
2020.10.16
Released
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 WIRELESS SOLUTIONS LIMITED COPYING, TO OTHERS AND USING THIS DOCUMENT,
ARE FORBIDDEN WITHOUT EXPRESS AUTHORITY BY SIMCOM. OFFENDERS ARE LIABLE TO THE
PAYMENT OF INDEMNIFICATIONS. ALL RIGHTS RESERVED BY SIMCOM IN THE PROPRIETARY
TECHNICAL INFORMATION ,INCLUDING BUT NOT LIMITED TO REGISTRATION GRANTING OF A
PATENT , A UTILITY MODEL OR DESIGN. ALL SPECIFICATION SUPPLIED HEREIN ARE SUBJECT TO
CHANGE WITHOUT NOTICE AT ANY TIME.
SIMCom Wireless Solutions Limited
Building B, SIM Technology Building, No.633 Jinzhong Road, Changning District, Shanghai P.R. China
Tel: +86 21 31575100
Email: simcom@simcom.com
For more information, please visit:
https://www.simcom.com/download/list-863-en.html
For technical support, or to report documentation errors, please visit:
https://www.simcom.com/ask/ or email to: support@simcom.com
Copyright © 2020 SIMCom Wireless Solutions Limited All Rights Reserved.
www.simcom.com
2 / 16
SIM800 Series_MQTT_Application Note_V1.03
About Document
Version History
Version Date
1.00
1.01
2017-10-11
2019-12-10
Owner
Dingfen.Zhu
Xiaohui.Xu
1.02
1.03
2020-06-15
Yizhe.Tan
/Wenjie.Lai
2020-10-16 Wenjie.Lai
What is new
Original
Chapter 2.2, Add AT+SAZURECONF
Chapter 3.2, Add MQTT Connecting to Azure IoT
Modify format and style
Chapter 4.1,Modidy examples and format
Scope
This document presents the AT command of MQTT operation and application examples. This document can
apply to SIM800 series modules with MQTT function.
www.simcom.com
3 / 16
SIM800 Series_MQTT_Application Note_V1.03
Contents
About Document.................................................................................................................................. 3
Version History.........................................................................................................................................................3
Scope........................................................................................................................................................................ 3
Contents................................................................................................................................................. 4
Introduction.................................................................................................................................... 5
1
Purpose of the document...........................................................................................................................5
1.1
Related documents.....................................................................................................................................5
1.2
Conventions and abbreviations................................................................................................................ 5
1.3
2 MQTT Introduction........................................................................................................................6
3 AT Commands for MQTT.............................................................................................................7
AT+SMCONF Set MQTT Parameter.................................................................................................... 7
3.1
AT+SAZURECONF Set Azure IoT Parameter.................................................................................... 8
3.2
AT+SMCONN MQTT Connection..........................................................................................................8
3.3
AT+SMSUB Subscribe Packet...............................................................................................................9
3.4
AT+SMPUB Publish Packet................................................................................................................... 9
3.5
AT+SMUNSUB Unsubscribe Packet.................................................................................................. 10
3.6
AT+SMSTATE Inquire MQTT Connection Status............................................................................. 11
3.7
AT+SMDISC Disconnect MQTT.......................................................................................................... 11
3.8
AT+SMSSL Set MQTT to Use SSL Function.................................................................................... 11
3.9
3.10 +SMPUBLISH Received Data............................................................................................................. 12
4 MQTT Examples.......................................................................................................................... 13
Standard MQTT.........................................................................................................................................13
4.1
4.2 MQTT Connecting to Azure IoT..............................................................................................................14
www.simcom.com
4 / 16
SIM800 Series_MQTT_Application Note_V1.03
1 Introduction
1.1Purpose of the document
Based on module AT command manual, this document will introduce MQTT application process.
Developers could understand and develop application quickly and efficiently based on this document.
1.2Related documents
[1] SIM800 Series_AT Command Manual
1.3Conventions and abbreviations
Abbreviations
GPRS
PDP
MQTT
Description
General Packet Radio Service
Packet Data Protocol
Message Queuing Telemetry Transport
www.simcom.com
5 / 16
SIM800 Series_MQTT_Application Note_V1.03
2 MQTT Introduction
MQTT (Message Queue Telemetry Transport) is a messaging protocol based on the publish/subscribe
paradigm under the ISO standard (ISO/IEC PRF 20922).
The MQTT protocol is a protocol designed for the communication of remote sensors and control devices
with limited computing power and working on low-bandwidth, unreliable networks. It has the following main
features:
1) Use the publish/subscribe message mode to provide one-to-many message publishing and
uncouple application.
2) Message transmission blocked by the payload content.
3) Provide network connectivity using TCP/IP.
4) There are three types of message publishing service quality:
“At most once”, the message is completely dependent on the underlying TCP/IP network.
Message loss or duplication can occur. This level can be used in the following situations, environmental
sensor data, loss of a read record does not matter, because there will be a second transmission in the near
future.
“At least once” to ensure that the message arrives, but message duplication may occur.
“Only once” to ensure that the message arrives once. This level can be used in situations where
repeated or missing messages can result in incorrect results.
5) Small transmission, low overhead (fixed length header is 2 bytes), protocol exchange is minimized
to reduce network traffic.
6) Use Last Will and Testament features to notify the mechanism of abnormal client interruption.
www.simcom.com
6 / 16
SIM800 Series_MQTT_Application Note_V1.03
3 AT Commands for MQTT
SIM800 series modules provide MQTT AT command is as follows:
AT Command
AT+SMCONF
AT+SAZURECONF
AT+SMCONN
AT+SMSUB
AT+SMUNSUB
AT+SMPUB
AT+SMSTATE
AT+SMDISC
AT+SMSSL
+SMPUBLISH
Description
Set MQTT Parameter
Set Azure IoT Parameter
MQTT Connection
Subscribe Packet
Unsubscribe Packet
Publish Packet
Inquire MQTT Connection Status
Disconnect MQTT
Set MQTT to Use SSL Function
Received Data
3.1AT+SMCONF Set MQTT Parameter
AT+SMCONF Set MQTT Parameter
Response
Test Command
AT+SMCONF=?
+SMCONF: "MQTTParamTag","MQTTParamValue"
Read Command
AT+SMCONF?
OK
Response
+SMCONF: ,
Write Command
AT+SMCONF=,
OK.
Response
OK
or
+CME ERROR:
Parameters
MQTT Parameter
Bearer profile identifier
"CID"
"URL" MQTT Server URL
www.simcom.com
7 / 16
SIM800 Series_MQTT_Application Note_V1.03
"serve:tcpPort"
"server": FQDN or IP-address
"tcpPort": default value is 1883
"CLIENTID" Client connection id. Default is NULL.
"KEEPALIVE" Hold connect time.default:60,Range: (60-3600)
"CLEANSS" Clean session flag,default:0,Range:(0-1)
"USERNAME" User name. default null
"PASSWORD" Password,default null
"TIMEOUT" MQTT response timeout value
Reference
MQTT Parameter value
Note
3.2AT+SAZURECONF Set Azure IoT Parameter
AT+SAZURECONF Set Azure IoT Parameter
Test Command
AT+SAZURECONF=?
Response
+SAZURECONF: "url","deviceId","deviceKey",
Write Command
AT+SAZURECONF=,
,,
OK
Response
OK
or
+CME ERROR:
Parameters
< URL> Azure IoT HostName
"serve:tcpPort"
"server": HostName
"tcpPort": Port need to configure to 8883.
The Id of the Azure IoT Device.
The "PrimaryKey" of the Azure IoT Device.
Expiration time,Rang:0~3600*24*365(second).
Note
Reference
3.3 AT+SMCONN MQTT Connection
AT+SMCONN MQTT Connection
www.simcom.com
8 / 16