AT command controls ESP8266

What I am using is ESP8266-01S. The basic functions of AT commands can be used directly, but to upload data to the IoT platform, you need to download the MQTT firmware. At first, I consulted other information on CSDN. When downloading the firmware library, the pins are generally connected to IO0 to ground, VCC to 3.3V, RX to TX of CH340, TX to RX of CH340, and GND to GND. After trying for a long time, the download failed. Finally, after checking the information provided by Taobao, I found that my pins are like this. Only in this way can I download the MQTT firmware.

 Select the pin in download mode to download successfully. The download tool is the ESP burning tool. Find the gear icon to open it and select ESP8266.

Then select the MQTT file. Generally, 1471 is used. The parameters are as shown in the figure.

COM is connected to the CH340 according to the computer. You can view the COM port in the computer settings, click REASE, unplug the power of ESP8266 and plug it in again, click START, unplug the power of ESP8266 and plug it in again, and wait for downloading. After completing the download, the ESP8266 can use the MQTT firmware. When sending AT+GMR in the serial port assistant, you can find that there is an extra line with a description of bin.

To enable ESP8266 to upload data to the Internet of Things platform, the platform I use is the Alibaba Cloud platform. To create products on the Alibaba Cloud platform, the URL is as follows: Alibaba Cloud Login - Welcome to Alibaba Cloud, a safe and stable cloud computing service platform

If you don’t have an account, you must first register an account and create a product.

 In Device-Device List-Add Device

 

 Here, select the product you just created. You can enter your favorite device name, or you can click Confirm to automatically generate it.

 

It will pop up after confirmation

 Click to view device information

 The MQTT connection parameters here are very important and will be used frequently when the ESP8266 is connected later.

Go back to product-function definition-edit draft, here is the uploaded data settings

Here you can customize or choose standard 

This is what it looks like after confirmation

Click Publish in the upper right corner and tick √ and Publish

 

AT-MQTT command manual: MQTT AT Commands — ESP-AT user guide document , you can view its parameters in detail

When using the serial port assistant, be sure to check automatic line wrapping. By the way, this is the connection between CH340 and ESP8266. Mine is VCC connected to 3.3V, RX connected to TX of CH340, TX connected to RX of CH340, GND connected to GND. EN is connected to 3.3V

1.Reset operation

AT+RST                                            

2.Restore factory settings

AT+RESTORE

3. Set SEP8266 mode, either 1 or 3 is acceptable here

AT+CWMODE=3

4. Connect to wifi. This wifi can be a hotspot on your mobile phone. You need to be able to access the Internet. Fill in the wifi name and password.

AT+CWJAP="WIFIname","WIFIpasswd"

This reply indicates that the connection is successful. At this time, check the mobile hotspot and see that a device has been connected.

5. Start the SNTP server, time domain 8, the SNTP server is the Alibaba Cloud domain name, the parameters do not need to be changed, just send them directly.

AT+CIPSNTPCFG=1,8,"ntp1.aliyun.com"

6. Configure the MQTT user attributes, change the third and fourth parameters, these two parameters are the MQTT connection parameters mentioned earlier, and find the parameters corresponding to username and passwd. (If the parameters are too long, it is recommended to write them in notepad and then paste them into the serial port assistant, otherwise they will cause line breaks by mistake and cause an error)

AT+MQTTUSERCFG=0,1,"NULL","username","passwd",0,0,""

7. Configure the MQTT client ID and change the second parameter. This parameter is also obtained from the MQTT connection parameters mentioned earlier. If there is a comma, add \ before the comma.

AT+MQTTCLIENTID=0,"clientId"

8. Connect/query MQTT Broker and change the second and third parameters. These two parameters are also obtained from the MQTT connection parameters mentioned earlier.

AT+MQTTCONN=0,"mqttHostUrl",port,1

After reaching this step, you can see on the Alibaba Cloud platform that the device is connected and online.

9. If you want to communicate, you need to subscribe. Change the second parameter. Fill in the blank space with the parameter before the first | symbol in clientId in the MQTT connection parameters mentioned earlier. Change . to /

AT+MQTTSUB=0,"/      /user/get",1

You can see on the Alibaba Cloud platform that you have subscribed to the topic

10. Issue the command. The first empty space is the same as the parameter in step 9. The second empty space is the identifier parameter defined by the function. The third empty space is the data you want to send.

AT+MQTTPUB=0,"/sys/    /thing/event/property/post","{params:{\"    \":    }}",0,0

After sending successfully, you can view the data you sent on Alibaba Cloud.

11. You can post messages here. It is here that you can send data to ESP8266 on Alibaba Cloud to the serial port assistant.

 

You can view it in the serial port assistant

11. In order to save resources, you can close the connection

AT+MQTTCLEAN=0

This is my study note, stm32 control ESP8266 update to be continued......

Guess you like

Origin blog.csdn.net/m0_71827453/article/details/132210726