SIM800 Series MQTT Application Note V1.03
SIM800 Series MQTT Application Note V1.03
_Application Note
GPRS Module
GENERAL NOTES
COPYRIGHT
www.simcom.com 2 / 16
SIM800 Series_MQTT_Application Note_V1.03
About Document
Version History
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
1 Introduction.................................................................................................................................... 5
1.1 Purpose of the document...........................................................................................................................5
1.2 Related documents.....................................................................................................................................5
1.3 Conventions and abbreviations................................................................................................................ 5
2 MQTT Introduction........................................................................................................................6
3 AT Commands for MQTT.............................................................................................................7
3.1 AT+SMCONF Set MQTT Parameter.................................................................................................... 7
3.2 AT+SAZURECONF Set Azure IoT Parameter.................................................................................... 8
3.3 AT+SMCONN MQTT Connection..........................................................................................................8
3.4 AT+SMSUB Subscribe Packet...............................................................................................................9
3.5 AT+SMPUB Publish Packet................................................................................................................... 9
3.6 AT+SMUNSUB Unsubscribe Packet.................................................................................................. 10
3.7 AT+SMSTATE Inquire MQTT Connection Status............................................................................. 11
3.8 AT+SMDISC Disconnect MQTT.......................................................................................................... 11
3.9 AT+SMSSL Set MQTT to Use SSL Function.................................................................................... 11
3.10 +SMPUBLISH Received Data............................................................................................................. 12
4 MQTT Examples.......................................................................................................................... 13
4.1 Standard MQTT.........................................................................................................................................13
4.2 MQTT Connecting to Azure IoT..............................................................................................................14
www.simcom.com 4 / 16
SIM800 Series_MQTT_Application Note_V1.03
1 Introduction
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.
Abbreviations Description
GPRS General Packet Radio Service
PDP Packet Data Protocol
MQTT 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.
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
AT Command Description
AT+SMCONF Set MQTT Parameter
AT+SAZURECONF Set Azure IoT Parameter
AT+SMCONN MQTT Connection
AT+SMSUB Subscribe Packet
AT+SMUNSUB Unsubscribe Packet
AT+SMPUB Publish Packet
AT+SMSTATE Inquire MQTT Connection Status
AT+SMDISC Disconnect MQTT
AT+SMSSL Set MQTT to Use SSL Function
+SMPUBLISH Received Data
OK
Read Command Response
AT+SMCONF? +SMCONF: <MQTTParamTag>,<MQTTParamValue>
OK.
Write Command Response
AT+SMCONF=<MQTTParam OK
Tag>,<MQTTParamValue> or
+CME ERROR: <err>
Parameters
<MQTTParamTag> MQTT Parameter
"CID" Bearer profile identifier
"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
OK
Write Command Response
AT+SAZURECONF=<URL>, OK
<DeviceId>,<DeviceKey>,<E or
xpiry_time> +CME ERROR: <err>
Parameters
< URL> Azure IoT HostName
"serve:tcpPort"
"server": HostName
"tcpPort": Port need to configure to 8883.
<DeviceId> The Id of the Azure IoT Device.
<DeviceKey> The "PrimaryKey" of the Azure IoT Device.
<expiry_time> Expiration time,Rang:0~3600*24*365(second).
Reference Note
www.simcom.com 8 / 16
SIM800 Series_MQTT_Application Note_V1.03
OK
Write Command Response
AT+SMSUB=<topic>,<qos> OK
or
+CME ERROR: <err>
www.simcom.com 9 / 16
SIM800 Series_MQTT_Application Note_V1.03
OK
Write Command Response
AT+SMPUB=<topic>,<qos>, OK
<retain>,<message> or
+CME ERROR: <err>
OK
Write Command Response
AT+SMUNSUB=<topic> OK
or
+CME ERROR: <err>
Parameters
<topic> Topic name
<packet_id> Packet id
<status> Unsubscribe status
0 Success
www.simcom.com 10 / 16
SIM800 Series_MQTT_Application Note_V1.03
1 Time Out
2 Other Error
Reference Note
OK
Parameters
<status>
0 Disconnect status
1 Connect status
Reference Note
www.simcom.com 11 / 16
SIM800 Series_MQTT_Application Note_V1.03
OK
Read Command Response
AT+SMSSL? +SMSSL: <Enable>
OK
Write Command Response
AT+SMSSL=<Enable> OK
or
+CME ERROR: <err>
Parameters
<Enable>
0 Disable SSL function
1 Enable SSL function
Reference Note
www.simcom.com 12 / 16
SIM800 Series_MQTT_Application Note_V1.03
4 MQTT Examples
The following table provides some using method of the MQTT function.
OK
AT+SMCONF="URL","117.131.85.139:6000" //Set parameters for MQTT
OK
AT+SMCONF="CLEANSS",1
OK
AT+SMCONN //MQTT Connection
OK
AT+SMSUB="Topic1",1 //Subscribe topic
OK //Subscribe response
+SMSUB: 1,0
+SMPUB: 2,0
www.simcom.com 13 / 16
SIM800 Series_MQTT_Application Note_V1.03
+SMUNSUB: 3,0
AT+SMDISC //Disconnect MQTT
OK
AT+SAPBR=0,1 //To close a GPRS context.
OK
The following table provides the example of MQTT Connecting to Azure IoT.
OK
OK
AT+SAPBR=3,1,"Contype","GPRS" //Configure bearer profile 1
OK
AT+SAPBR=3,1,"APN","CMNET" //Enable wireless connection, this parameter needs
to set different APN values according to different
cards.
OK
AT+SAPBR=1,1 //To open a GPRS context
OK
AT+SAPBR=2,1 //To query the GPRS context
+SAPBR: 1,1,"10.156.5.253"
OK
www.simcom.com 14 / 16
SIM800 Series_MQTT_Application Note_V1.03
+SMSUB: 1,0
+SMPUB: 2,0
//If successful, you can receive the published
message “hello world” from Azure IoT.
AT+SMDISC //Disconnect MQTT
www.simcom.com 15 / 16
SIM800 Series_MQTT_Application Note_V1.03
OK
AT+SAPBR=0,1 //To close a GPRS context.
OK
www.simcom.com 16 / 16