-
1MQTT AT command of A9/A9G
1. Overview of AT commands for MQTT
Command Description
AT+MQTTCONN Send MQTT connection packet
AT+MQTTSUB Send MQTT subscribe packet
AT+MQTTPUB Send MQTT publish packet
AT+MQTTDISCONN Disconnect MQTT
2. Detailed Descriptions of AT Commands
2.1 AT+MQTTCONN Send MQTT connection packet
AT+MQTTCONN=<host>,<port>,<clientid>,<aliveSeconds>,<cleansession>,<username>,<password>
Response :
success OK
failure +CME ERROR:<err>
Parameters:
<host> MQTT server name or server IP address
<port> MQTT server port
<clientid> Client ID, should be unique
<aliveSeconds> Keep alive interval
<cleansession> Cean session, can be 0 or 1
<username> User name (option)
<password> Password (option)
Example:
1.Not enter username and password
AT+MQTTCONN="www.mqtt-dashboard.com",1883,"12345",120,0
OK
2. Enter username and password
AT+MQTTCONN="www.mqtt-dashboard.com",1883,"12345",120,0,"Ai-thinker","123456"
OK
2.2 AT+MQTTSUB Send MQTT subscribe packet
AT+MQTTSIN=<topic>,<sub>,<qos>
Response :
success OK
failure +CME ERROR:<err>
Parameters:
<topic> Topic of subscribe message
<sub> Subscribe flag, can be 0 or 1
<qos> Message QoS, can be 0, 1 or 2.
Example:
AT+MQTTSUB="test",1,0
+MQTTPUBLISH:1,app, 10,1234567890
OK2.3 AT+MQTTPUB Send MQTT publish packet
AT+MQTTPUB=<topic>,<payload>,<qos>,<dup>,<remain>
Response :
success OK
failure +CME ERROR:<err>
Parameters:
<topic> Topic of subscribe message
<payload> Publish message
<dub> Duplicate flag, can be 0 or 1
<qos> Message QoS, can be 0, 1 or 2.
<remain> Retained flag, can be 0 or 1.
Example:
AT+MQTTPUB="test","123456",0,0,0
OK
AT+MQTTPUB=<topic>,<payloadlength>,<payload>,<qos>,<dup>,<remain>
Response :
success OK
failure +CME ERROR:<err>
Parameters:
<topic> Topic of subscribe message
<payloadlength> Publish message length
<payload> Publish message
<dub> Duplicate flag, can be 0 or 1
<qos> Message QoS, can be 0, 1 or 2.
<remain> Retained flag, can be 0 or 1.
Example:
AT+MQTTPUB="test",5,0,0,0
>12345
OK
2.4 AT+MQTTDISCONN Disconnect MQTT
Response :
success OK
failure +CME ERROR:<err>
2.5 Example of the A9 A9G MQTT
AT+ CGATT=1 //connect to the network
OK
AT+CGDCONT=1,"IP","CMNET" // Set PDP Parameters
OK
AT+CGACT=1,1 //Active the PDP
OK
AT+MQTTCONN="www.anthinkerwx.com",1883,"12345",120,0,”ai-thinker”,”123456” //Client connect to the mqtt server
OK
AT+MQTTPUB="test","124563",0,0,0 //Publish a massage
OK
AT+MQTTSUB="test",1,0 //Send MQTT subscribe packet
OK
AT+MQTTDISCONNN // Disconnect the mqtt server
OK
-
2Hardware connection​
Wire the DHT11 to the ESP-12S A9G GPRS GPS Node as shown in the following schematic diagram.
Also install the Noao SIM card and Plug the Lipo battery and USB.
-
3ThingSpeak
ThingSpeak is where we are going to store the data collected by our thing and where we can see the data that we collected. Visit ThingSpeak.com and Sign Up for an account. This will just take a minute and user accounts are free. Once you have a user account, you need to create a channel. ThingSpeak channels are where data gets stored. Create a new channel by selecting Channels, My Channels, and then New Channel. Name the channel, “ESP-12S A9G DHT11” and name Field 1, “temp”, Field 2:"hum".Click “Save Channel” at the bottom to finish the process.
-
4Arduino Setup
we need to install some software to be able to program the ESP8266. Visit Arduino.cc and install the Arduino IDE.
More detail please refer our wiki.
-
5Arduino Library
Downlaod and Installing the Adafruit DHT11 and Sensor Library. Unzip the .zip file and place them to the Arduino librarys.
-
6Code
Copy the following code to your Arduino IDE but don’t upload it yet. First, you need to make some modifications to make it work.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Hi
I have a problem connecting to MQTT ThingSpeak.
Command for connection is:
String msg = sendData("AT+MQTTCONN=\"mqtt.thingspeak.com\",1883,\"1020492\",120,0,\"1020492\",\"3QP8L2FUMH4O7A5E\"", 1000, DEBUG);
Response from serial monitor is:
18:37:48.072 -> AT+MQTTCONN="mqtt.thingspeak.com",1883,"1020492",120,0,"1020492","3QP8L2FUMH4O7A5E"
18:37:48.118 ->
18:37:48.118 -> +CME ERROR: 53
What is wrong with my parameters?
Are you sure? yes | no
Did your fix it, i get the same!
Are you sure? yes | no