Usage Example for Easy IoT Platform - MQTT Communication

Last revision 2025/12/31

This article is a detailed guide on how to use AT commands to establish MQTT connections through devices like the Air780EU module. It covers hardware setup, command usage, and step-by-step operations for sending messages to servers, providing valuable insights for IoT enthusiasts and developers.

Hardware Preparation

  • This module supports USB drivers under Windows 7/8/8.1/10, Linux, Android and other operating systems, so no need to install drivers.
  • This AT command is case insensitive.
  • Upon connecting the module to a computer, three COM ports will appear, of which only one is designated for AT command debugging. The remaining two COM ports are not operational.

Command set used

Command Meaning Return Value
AT+CPIN? Query whether sim card is normal +CPIN: READY
AT+CGATT? Query whether it is attached to the data network +CGATT: 1
AT+MCONFIG="clientid","user","password" Set MQTT related parameters OK
AT+MIPSTART="svraddr","port" Establish TCP connection CONNECT OK
AT+MCONNECT=clean_session, keepalive Client requests session connection to server CONNACK OK
AT+MSUB="topic",qos Subscribe to topic SUBACK
AT+MPUB="topic",qos,retain,"message" Publish message

Operation steps: send a message to the target server

Enter Easy IoT. If you do not possess an account, you may commence by registering one.

Upon successful login, proceed to open your workspace. Retrieve your credentials: username, password. Then, proceed to add a novel device, denoted as a Topic, and meticulously document the aforementioned three pivotal parameters.

Easy IoT

  1. Open SSCOM Assistant, send AT+CPIN? to query if the SIM card is normal. If +CPIN: READY is returned, it indicates that the SIM card is normal. If +CME ERROR: 10 is returned, it means that the SIM card is not inserted.

  2. AT+CGATT? queries whether it is attached to the data network. +CGATT: 1 indicates that the current GPRS is already attached. If +CGATT: 0 is returned, it indicates that it is not attached.

  3. AT+MCONFIG="12345678987","user","password" (Set MQTT related parameters, in this example, "clientid" is customized as "12345678987", the customized "clientid" has a maximum of 256 bytes and cannot be the same, otherwise, the last one just connected to the server will be kicked off; enter the account (user) and password (password) obtained on the Easy IoT platform in "user" and "password" respectively)

  4. AT+MIPSTART="iot.dfrobot.com","1883" (Establish TCP connection, Note: Receiving OK only means that the 4G module starts to process this command, and does not mean that TCP is successfully connected; only when CONNECT OK is received is the successful response. If other responses are received, you can refer to the AT manual in the additional information at the bottom of the document)

  5. AT+MCONNECT=1,60 (The client requests a session connection to the server, where "1" means to establish a new session, "60" means that at least one message needs to be sent within 60 seconds of the keep-alive time, including PING request, otherwise the connection will be disconnected, and the device side needs to initiate a reconnection. The range of keep-alive time is 1-65535. Note: After sending the MCONNECT command, receiving OK only means that the 4G module starts to process this command, and does not mean that MQTT is successfully connected; only when CONNACK OK is received is the successful response)

  6. AT+MSUB="mqtt/sub_topic",0 (Subscribe to the topic, where "mqtt/sub_topic" represents the topic (Topic) obtained on the Easy IoT platform, and "0" represents subscribing to the topic at most once. Note: After sending the MSUB command, receiving OK only means that the 4G module starts to process this command, and does not mean that MQTT has successfully subscribed; only when SUBACK is received is the successful response)

  7. AT+MPUB="mqtt/pub_topic",2,0,"HELLO DFROBOT" (Publish message, "mqtt/sub_topic" represents the topic (Topic) obtained on the Easy IoT platform, the second parameter indicates that only one message is published, the third parameter is the retention flag, generally set to 0, the server does not store this message and cannot remove or replace any existing retention messages; the fourth parameter is the content of the published message, up to 4100 bytes. If you publish at least one message, you need to change the second parameter to "1", if you publish at most one message, you need to change the second parameter to "0" Note: After sending the MPUB command, if QOS is not 0, then receiving OK only means that the 4G module starts to process this command, and does not mean that MQTT has successfully published; only when PUBACK (when QOS is 1) or PUBCOMP (when QOS is 2) is received is the successful response)

    success1

  8. Finally, enter the Easy IoT workspace, check the details of the created topic, and query the information received from the module.

    success2

All published commands need to check "Add Carriage Return Line Feed"**

Was this article helpful?

TOP