페이지 선택
Generic selectors
Exact matches only
Search in title
Search in content
Search in pages
AT Commands For MQTT(S)

  

Command Description
AT+CMQTTSTART Start MQTT service
AT+CMQTTSTOP STOP MQTT service
AT+CMQTTACCQ Acquire a client
AT+CMQTTREL Release a client
AT+CMQTTSSLCFG Set the SSL context
AT+CMQTTWILLTOPIC Input the will topic
AT+CMQTTWILLMSG Input the will message
AT+CMQTTCONNECT Connect to MQTT server
AT+CMQTTDISC Disconnect from server
AT+CMQTTTOPIC Input the publish message topic
AT+CMQTTPAYLOAD Input the publish message body
AT+CMQTTPUB Publish a message to server
AT+CMQTTSUBTOPIC Input a subscribe message topic
AT+CMQTTSUB Subscribe a message to server
AT+CMQTTUNSUBTOPIC Input a unsubscribe message topic
AT+CMQTTUNSUB Unsubscribe a message to server
AT+CMQTTCFG Configure the MQTT Context

 

 

 

 

AT+CMQTTSTART     Start MQTT Service

 

E) AT+CMQTTSTART

OK

 

+CMQTTSTART: <err>

or

+CMQTTSTART: <err>

 

OK

or

ERROR

 

+CMQTTSTART: <err>

or

+CMQTTSTART: <err>

 

ERROR

or

ERROR

 

 

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTSTART

OK

 

+CMQTTSTART: 0

 

NOTE

It must be executed before any other MQTT related operations

 

 

 

 

AT+CMQTTSTOP    Stop MQTT Service

 

E) AT+CMQTTSTOP

OK

 

+CMQTTSTOP: <err>

or

+CMQTTSTOP: <err>

 

OK

or

ERROR

 

+CMQTTSTOP: <err>

or

+CMQTTSTOP: <err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

 

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTSTOP

OK

 

+CMQTTSTOP: 0

 

 

 

 

AT+CMQTTACCQ     Acquire A Client

  

T) AT+CMQTTACCQ=?

+CMQTTACCQ: (0-1),(1-128),(0-1),(3-4)

 

OK

R) AT+CMQTTACCQ?

+CMQTTACCQ:     <client_index>,<clientID>,<server_type>

+CMQTTACCQ:     <client_index>,<clientID>,<server_type>

 

OK

W) AT+CMQTTACCQ=<client_i ndex>,<clientID>[,<server_type>[,<mqtt_version>]]

OK

or

+CMQTTACCQ: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<clientID>

The UTF-encoded string.

It specifies a unique identifier for the client.

The string length is from 1 to 128 bytes.

<server_type>

A numeric parameter that identifies the server type.

The default value is 0.

0  – MQTT server with TCP

1  – MQTT server with SSL/TLS

<mqtt_version>

A numeric parameter that identifies the MQTT protocol version.

The permitted value is 3 or 4.

3  – MQTT version 3.1

4  – MQTT version 3.1.1

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTACCQ=0,”client test0″,0,4

OK

 

NOTE

It must be called before all commands about MQTT connect and after AT+CMQTTSTART

 

 

 

 

AT+CMQTTREL     Release A Client

 

T) AT+CMQTTREL=?

+CMQTTREL: (0-1)

 

OK

R) AT+CMQTTREL? OK
W) AT+CMQTTREL=<client_index>

OK

or

+CMQTTREL: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  
 

  

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTREL=0

OK

 

 NOTE

It must be called after AT+CMQTTDISC and before AT+CMQTTSTOP

 

 

 

 

AT+CMQTTSSLCFG    Set The SSL Context

  

T) AT+CMQTTSSLCFG=?

+CMQTTSSLCFG: (0,1),(0-9)

 

OK

R) AT+CMQTTSSLCFG?

+CMQTTSSLCFG: <session_id>,[<ssl_ctx_index >]

+CMQTTSSLCFG: <session_id>,[<ssl_ctx_index >]

 

OK

W) AT+CMQTTSSLCFG=<session_id>,<ssl_ctx_index>

OK

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

  

<session_id>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<ssl_ctx_index>

The SSL context ID which will be used in the SSL connection.

Refer to the <ssl_ctx_index> of AT+CSSLCFG

 

 

Example

AT+CMQTTSSLCFG=0,1

OK

 

 NOTE

If you don’t set the SSL context by this command before connecting to server by AT+CMQTTCONNECT,

the CMQTTCONNECT operation will use the SSL context as same as index <session_id> (the 1st parameter of AT+ CMQTTCONNECT) when connecting to the server

 

 

 

 

AT+CMQTTWILLTOPIC     Input The Will Topic

  

T) AT+CMQTTWILLTOPIC=?

+CMQTTWILLTOPIC: (0-1),(1-1024)

 

OK

W) AT+CMQTTWILLTOPIC=<client_index>,<req_length>

> 

<input data here>

OK

or

+CMQTTWILLTOPIC: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic.

The will topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTWILLTOPIC=0,15

>simcomwilltopic

OK

 

 

 

 

AT+CMQTTWILLMSG     Input The Will Message

  

T) AT+CMQTTWILLMSG=?

+CMQTTWILLMSG: (0-1),(1-1024),(0-2)

 

OK

W) AT+CMQTTWILLMSG=<client_index>,<req_length>,<qos>

> 

<input data here>

OK

or

+CMQTTWILLMSG: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

  

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input data.

The will message should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<qos>

The qos value of the will message.

The range is from 0 to 2.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTWILLMSG=0,17,0

>simcomwillmessage

OK

 

 

 

 

 AT+CMQTTDISC     Disconnect From Server

 

T) AT+CMQTTDISC=?

+CMQTTDISC: (0-1),(0,60-180)

 

OK

R) AT+CMQTTDISC?

+CMQTTDISC: 0,<disc_state>

+CMQTTDISC: 1,<disc_state>

 

OK

W) AT+CMQTTDISC=<client_index>,<timeout>

OK

 

+CMQTTDISC: <client_index>,<err>

or

+CMQTTDISC: <client_index>,<err>

 

OK

or

+CMQTTDISC: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<timeout>

The timeout value for disconnection.

The unit is second.

The range is 60s to 180s.

The default value is 0s (not set the timeout value)

<disc_state>

1 – disconnection

0 – connection

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTDISC=0,120

OK

 

+CMQTTDISC: 0,0

 

 

 

 

AT+CMQTTCONNECT     Connect To MQTT Server

  

T) AT+CMQTTCONNECT=?

+CMQTTCONNECT: (0-1),(9-256),(1-64800),(0-1)

 

OK

R) AT+CMQTTCONNECT?

+CMQTTCONNECT:

0[,<server_addr>,<keepalive_time>,<clean_session>[,<user_name>[,<pass_word>]]]

+CMQTTCONNECT:

1[,<server_addr>,<keepalive_time>,<clean_session>[,<user_name>[,<pass_word>]]]

 

OK

W) AT+CMQTTCONNECT=<client_index>,<server_addr>,<keepalive_time>,<clean_session>[,<user_name>[,<pass_word>]]

OK

 

+CMQTTCONNECT: <client_index>,<err>

or

+CMQTTCONNECT: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  
 

  

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<server_addr>

The string that described the server address and port.

The range of the string length is 9 to 256 bytes.

The string should be like this “tcp://116.247.119.165:5141”, must begin with “tcp://”.

If the <server_addr> not include the port, the default port is 1883.

<keepalive_time>

The time interval between two messages received from a client.

The client will send a keep-alive packet when there is no message sent to server after song long time.

The range is from 1s to 64800s (18 hours)

<clean_session>

The clean session flag.

The value range is from 0 to 1, and default value is 0.

0     – the server must store the subscriptions of the client after it disconnected.

This includes continuing to store QoS 1 and QoS 2 messages for the subscribed topics so that they can be delivered when the client reconnects.

The server must also maintain the state of in-flight messages being delivered at the point the connection is lost.

This information must be kept until the client reconnects.

1    – the server must discard any previously maintained information about the client and treat the connection as “clean”.

The server must also discard any state when the client disconnects.

<user_name>

The user name identifies the name of the user which can be used for authentication when connecting to server.

The string length is from 1 to 256 bytes.

<password>

The password corresponding to the user which can be used for authentication when connecting to server.

The string length is from 1 to 256 bytes.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTCONNECT=0,”tcp://hooleeping.com:8883″,60,1

OK

+CMQTTCONNECT: 0,0    

 

NOTE

If you don’t set the SSL context by AT+CMQTTSSLCFG before connecting a SSL/TLS MQTT server by AT+CMQTTCONNECT,

it will use the <client_index> (the 1st parameter of AT+CMQTTCONNECT) SSL context when connecting to the server.

                                                                                                                     

 

 

 

AT+CMQTTTOPIC    Input The Publish Message Topic

 

T) AT+CMQTTTOPIC=?

+CMQTTTOPIC: (0-1),(1-1024)

 

OK

W) AT+CMQTTTOPIC=<client_index>,<req_length>

> 

<input data here>

OK

or

+CMQTTTOPIC: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic data.

The publish message topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTTOPIC=0,11

>simcomtopic

OK

 
NOTE

The topic will be clean after execute AT+CMQTTPUB

 

 

 

 

 AT+CMQTTPAYLOAD     Input The Publish Message Body

 

T) AT+CMQTTPAYLOAD=?

+CMQTTPAYLOAD: (0-1),(1-10240)

 

OK

W) AT+CMQTTPAYLOAD=<client_index>,<req_length>

> 

<input data here>

OK

+CMQTTPAYLOAD: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input message data.

The publish message should be UTF-encoded string.

The range is from 1 to 10240 bytes

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTPAYLOAD=0,13

>simcompayload

OK

 

NOTE

The payload will be clean after execute AT+CMQTTPUB

 

 

 

 

 AT+CMQTTPUB     Publish A Message To Server

 

T) AT+CMQTTPUB=?

+CMQTTPUB: (0-1),(0-2),(60-180),(0-1),(0-1)

 

OK

W) AT+CMQTTPUB=<client_index>,<qos>,<pub_timeout>[,<ratained> [,<dup>]]

OK

 

+CMQTTPUB: <client_index>,<err>

or

+CMQTTPUB: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<qos>

The publish message’s qos.

The range is from 0 to 2.

0 – at most once

1  – at least once

2  – exactly once

<pub_timeout>

The publishing timeout interval value.

Since the client publish a message to server, it will report failed if the client receive no response from server after the timeout value seconds.

The range is from 60s to 180s

<ratained>

The retain flag of the publish message.

The value is 0 or 1.

The default value is 0.

When a client sends a PUBLISH to a server, if the retain flag is set to 1,

the server should hold on to the message after it has been delivered to the current subscribers

<dup>

The dup flag to the message.

The value is 0 or 1.

The default value is 0.

The flag is set when the client or server attempts to re-deliver a message

<err> The result code, please refer to chapter 16.3.1
 

 

Example

AT+CMQTTPUB=0,0,120

OK

 

+CMQTTPUB: 0,0

 

 

 

 

AT+CMQTTSUBTOPIC    Input A Subscribe Message Topic

  

T) AT+CMQTTSUBTOPIC=?

+CMQTTSUBTOPIC: (0-1),(1-1024),(0-2)

 

OK

W) AT+CMQTTSUBTOPIC=<client_index>,<req_length>,<qos>

> 

<input data here>

OK

or

+CMQTTSUBTOPIC: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic data.

The publish message topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

NOTE: The max length of the total cached topics is 5120

<qos>

The publish message’s qos.

The range is from 0 to 2.

0 – at most once

1  – at least once

2  – exactly once

<err> The result code, please refer to chapter 16.3.1
 

 

Example

AT+CMQTTSUBTOPIC=0,11,0

>simcomtopic

OK

 

NOTE

The topic will be clean after execute AT+CMQTTSUB.

 

 

 

 

AT+CMQTTSUB    Subscribe A Message To Server

 

T) AT+CMQTTSUB=?

+CMQTTSUB: (0-1),(1-1024),(0-2),(0-1)

 

OK

W) 

AT+CMQTTSUB=<client_index>[,<dup>]

OK

 

+CMQTTSUB: <client_index>,<err>

or

+CMQTTSUB: <client_index>,<err>

 

ERROR

or

ERROR

W)  AT+CMQTTSUB=<client_index>,<reqLength>,<qos>[,<dup>]

Response

> 

<input data here>

OK

 

+CMQTTSUB: <client_index>,<err>

or

+CMQTTSUB: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic data.

The message topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<qos>

The publish message’s qos.

The range is from 0 to 2.

0 – at most once

1  – at least once

2  – exactly once

<dup>

The dup flag to the message.

The value is 0 or 1.

The default value is 0.

The flag is set when the client or server attempts to re-deliver a message.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTSUB=0

OK

 

+CMQTTSUB: 0,0

 

 

 

 

AT+CMQTTUNSUBTOPIC    Input A Unsubscribe Message Topic

 

T) AT+CMQTTUNSUBTOPIC=?

+CMQTTUNSUBTOPIC: (0-1),(1-1024)

 

OK

W) AT+CMQTTUNSUBTOPIC=<client_index>,<req_length>

> 

<input data here>

OK

or

+CMQTTUNSUBTOPIC: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic data.

The publish message topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTUNSUBTOPIC=0,11

>simcomtopic

OK

 

NOTE

The max length of the total cached topics is 5120.

The topic will be clean after execute AT+CMQTTUNSUB

 

 

 

 

AT+CMQTTUNSUB     Unsubscribe A Message To Server

  

T) AT+CMQTTUNSUB=?

+CMQTTUNSUB: (0-1),(1-1024),(0-1)

 

OK

W) 

AT+CMQTTUNSUB=<client_ index>,<dup>

OK

 

+CMQTTUNSUB: <client_index>,<err>

or

+CMQTTUNSUB: <client_index>,<err>

 

ERROR

or

ERROR

W) 

AT+CMQTTUNSUB=<client_ index>,<reqLength>,<dup>

> 

<input data here>

OK

 

+CMQTTUNSUB: <client_index>,<err>

or

+CMQTTUNSUB: <client_index>,<err>

 

ERROR

or

ERROR

Parameter Saving Mode
Maximum Response Time 120000ms
Reference  
 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<req_length>

The length of input topic data.

The message topic should be UTF-encoded string.

The range is from 1 to 1024 bytes.

<dup>

The dup flag to the message.

The value is 0 or 1.

The default value is 0.

The flag is set when the client or server attempts to re-deliver a message.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTUNSUB =0,0

OK

 

+CMQTTUNSUB: 0,0

 

 

 

 

AT+CMQTTCFG     Configure The MQTT Context

 

T) AT+CMQTTCFG=?

+CMQTTCFG: “checkUTF8”,(0-1),(0-1)

+CMQTTCFG: “optimeout”,(0-1),(20-120)

 

OK

R) AT+CMQTTCFG?

+CMQTTCFG: 0,<checkUTF8_flag>,<optimeout_val>

+CMQTTCFG: 1,<checkUTF8_flag>,<optimeout_val>

 

OK

W) AT+CMQTTCFG=”checkUTF8″,<client_index>,<checkUTF8_flag>

OK

or

+CMQTTCFG: <client_index>,<err>

 

OK

or

ERROR

W) AT+CMQTTCFG=”optimeout “,<client_index>,<optimeout_val>

OK

or

+CMQTTCFG: <client_index>,<err>

 

OK

or

ERROR

Parameter Saving Mode
Maximum Response Time
Reference  

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<checkUTF8_flag>

The flag to indicate whether to check the string is UTF8 coding or not, the default value is 1.

0  – Not check UTF8 coding.

1  – Check UTF8 coding.

<optimeout_val>

The max timeout interval of sending or receiving data operation.

The range is from 20 seconds to 120 seconds, the default value is 120 seconds.

<err> The result code, please refer to chapter 16.3.1

 

 

Example

AT+CMQTTCFG=”checkUTF8″,0,0 OK

AT+CMQTTCFG=”optimeout”,0,120

OK

 

NOTE

It must be called before AT+CMQTTCONNECT and after AT+CMQTTACCQ.

The setting will be cleared after AT+CMQTTREL

 

 

 

 

Summary Of Command Result <err> Codes

 

0 operation succeeded
1 failed
2 bad UTF-8 string
3 sock connect fail
4 sock create fail
5 sock close fail
6 message receive fail
7 network open fail
8 network close fail
9 network not opened
10 client index error
11 no connection
12 invalid parameter
13 not supported operation
14 client is busy
15 require connection fail
16 sock sending fail
17 timeout
18 topic is empty
19 client is used
20 client not acquired
21 client not released
22 length out of range
23 network is opened
24 packet fail
25 DNS error
26 socket is closed by server
27 connection refused: unaccepted protocol version
28 connection refused: identifier rejected
29 connection refused: server unavailable
30 connection refused: bad user name or password
31 connection refused: not authorized
32 handshake fail
33 not set certificate
34 open SSL session failed

 

 

 

 

Summary Of Unsolicited Result Codes

 

+CMQTTCONNLOST:

<client_index>,<cause>

When client disconnect passively, URC “+CMQTTCONNLOST” will be reported,

then user need to connect MQTT server again.

+CMQTTPING:

<client_index>,<err>

When send ping (which keep-alive to the server) to server failed, the module will report this URC.

If received this message, you should disconnect the connection and re-connect

+CMQTTNONET 

When the network is become no network, the module will report this URC.

If received this message, you should restart the MQTT service by AT+CMQTTSTART.

+CMQTTRXSTART:

<client_index>,<topic_total_len>,<payload_total_len>

+CMQTTRXTOPIC:

<client_index>,<sub_topic_len>

<sub_topic>

 

[<CR><LF>+CMQTTRXTOPIC:

<client_index>,<sub_topic_len>

<sub_topic>]

 

+CMQTTRXPAYLOAD:

<client_index>,<sub_payload_len>

<sub_payload>

[+CMQTTRXPAYLOAD:

<client_index>,<sub_payload_len>

<sub_payload>]

+CMQTTRXEND: <client_index>

 

If a client subscribes to one or more topics, any message published to those topics are sent by the server to the client.

The following URC is used for transmitting the message published from server to client.

 

1) +CMQTTRXSTART:

<client_index>,<topic_total_len>,<payload_total_len>

At the beginning of receiving published message, the module will report this to user, and indicate client index with <client_index>, the topic total length with <topic_total_len> and the payload total length with <payload_total_len>.

 

2) +CMQTTRXTOPIC:

<client_index>,<sub_topic_len>\r\n<sub_topic>

After the command “+CMQTTRXSTART” received, the module will report the second message to user, and indicate client index with <client_index>, the topic packet length with <sub_topic_len> and the topic content with <sub_topic> after “\r\n”.

For long topic, it will be split to multiple packets to report and the command “+CMQTTRXTOPIC” will be send more than once with the rest of topic content.

The sum of <sub_topic_len> is equal to <topic_total_len>.

 

3) +CMQTTRXPAYLOAD:

<client_index>,<sub_payload_len>\r\n<sub_payload>

After the command “+CMQTTRXTOPIC” received, the module will send  third   message   to  user,

and   indicate   client   index with <client_index>,

the   payload        packet       length       with <sub_payload_len> and the payload content with <sub_payload> after “\r\n”.

For long payload, the same as “+CMQTTRXTOPIC”.

 

4) +CMQTTRXEND: <client_index>

At last, the module will send fourth message to user and indicate the topic and payload have been transmitted completely.

 

 

<client_index>

A numeric parameter that identifies a client.

The range of permitted values is 0 to 1.

<cause>

The cause of disconnection.

1 – Socket is closed passively.

2 – Socket is reset.

3 – Network is closed.

<topic_total_len>

The length of message topic received from MQTT server.

The range is from 1 to 1024 bytes.

<payload_total_len>

The length of message body received from MQTT server. The range is

from 1 to 10240 bytes.

<sub_topic_len> The sub topic packet length, The sum of <sub_topic_len> is equal to <topic_total_len>.
<sub_topic> The sub topic content.
<sub_payload_len>

Max length is 1500. The sub message body packet length.

The sum of <sub_payload_len> is equal to <payload_total_len>.

<sub_payload> The sub message body content.
<err> The result code, please refer to chapter 16.3.1
 

Adsense

EMW3070

Viewed Page List