Usage Example for Easy IoT-MQTT Connection

Last revision 2025/12/31

This article offers a comprehensive guide on establishing an IoT-MQTT connection using the SIM7070G module, detailing hardware and software setup, and providing step-by-step MQTT configuration instructions with sample AT commands for seamless message publishing and server connectivity.

Hardware Preparation

Software Preparation

MQTT Connection step

Enter Easy IoT. If you don't have an account, you can register one first.
After successful login, open the workspace, get your account (user) and password, add a new device (Topic), and record the three important parameters.
Send the AT commands in the Sample Code sequence.

AT+CNACT=0,1

//Activate wireless connection, the first parameter '0' represents PDP Index, the second parameter '1' represents activation

AT+CNACT?

//Get local IP address

AT+SMCONF="URL","iot.dfrobot.com",1883

//Set MQTT server address and port, iot.dfrobot.com is the server address, 1883 is the default port of MQTT

AT+SMCONF="USERNAME","user"

//Set MQTT username, enter the account obtained on the Easy IoT platform in "user"

AT+SMCONF="PASSWORD","password"

//Set MQTT password, enter the password obtained on the Easy IoT platform in "password"

AT+SMCONF="CLIENTID","Topic"

//Set MQTT client ID, enter the device obtained on the Easy IoT platform in "Topic"

AT+SMCONF="CLEANSS",1

//Set to clear session, 1 means clear session

AT+SMCONF="KEEPTIME",60

//Set keep connection time, 60 means 60 seconds

AT+SMCONF="QOS",1

//Set message quality level, 1 means at least once

AT+SMCONF="RETAIN",1

//Set retain flag, 1 means message and its qos will be saved

AT+SMCONF="TOPIC","Topic"

//Set publish topic name, enter the device obtained on the Easy IoT platform in "Topic"

AT+SMCONF="MESSAGE","DFROBOT"

//Set publish message details, "DFROBOT" is the message content

AT+SMCONN

//Connect to MQTT server

AT+SMPUB="Topic",7,1,1

//Publish message, enter the device obtained on the Easy IoT platform in "Topic", 7 is the message length, 1 means retain message, 1 means message quality is 1, note: when publishing message, you need to check "return carriage"

//Then uncheck "return carriage" and send message content "DFROBOT"

AT+SMDISC

//Disconnect from MQTT server

AT+CNACT=0,0

//Disconnect wireless connection, the first parameter '0' represents PDP Index, the second parameter '0' represents disconnect.

Carriage return is also needed when publishing a message. When sending message content, cancel the carriage return.

Was this article helpful?

TOP