Bootstrap

ESP8266+阿里云(AT指令版)

        在确认阿里云配置无误后,下一步是尝试使用AT指令连接阿里云平台。这一步的主要目的是熟悉连接过程,并观察数据的发送和接收格式。通过使用AT指令,可以直接在设备端进行连接,而无需编写复杂的代码。这样可以更直观地了解连接的整个过程,包括身份认证、连接服务器、数据传输等环节。同时,通过观察数据的发送和接收格式,可以更好地理解设备与阿里云平台之间的通信方式,为后续的开发工作提供重要参考。

        在使用ESP8266进行与阿里云平台的通信之前,需要将ESP8266烧录MQTT固件,以便支持MQTT协议。对于想要了解更多关于ESP8266与阿里云平台通信的人来说,深入了解AT命令集是很有帮助的。AT命令集提供了详细的指令列表,涵盖了与Wi-Fi连接、MQTT配置、服务器连接、消息发布和订阅等相关的操作。通过加强对AT命令集的理解,可以更加清晰地了解每一步的操作流程,以及如何正确配置ESP8266以与阿里云平台进行通信。AT 命令集 - ESP32 - — ESP-AT 用户指南 latest 文档 (espressif.com)


步骤:

首先打开阿里云物联网平台-设备-查看-MQTT连接参数

AT指令:

1.启动

AT

2.设置为STA模式

AT+CWMODE=1

3. 连接wifi"WIFI名称","WIFI密码"

AT+CWJAP="WIFINAME","PASSWARD"

4. 配置 MQTT "clientId","username","passwd"(clientid中每个“逗号”前面都要加“\”进行转义)

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

5. 连接 MQTT Broker"mqttHostUrl

AT+MQTTCONN=0,"mqttHostUrl",1883,0

6.订阅主题,"产品-查看-Topic类列表-物模型通信Topic-设备属性设置"

AT+MQTTSUB=0,"/sys/${ProductKey}/${deviceName}/thing/service/property/set",0

7.发布主题,"产品-查看-Topic类列表-物模型通信Topic-设备属性上报"(JSON数据:上传的数据,此处为模拟值)

AT+MQTTPUB=0,"/sys/${ProductKey}/${deviceName}/thing/event/property/post","JSON数据",1,0

串口调试助手信息


[2024-05-05 10:22:01.854]
TX:AT

[2024-05-05 10:22:02.862]
RX:AT

OK

[2024-05-05 10:22:04.254]
TX:AT+CWMODE=1

[2024-05-05 10:22:05.273]
RX:AT+CWMODE=1

OK

[2024-05-05 10:22:06.238]
TX:AT+CWJAP="ALIYUN","12345678"

[2024-05-05 10:22:07.251]
RX:AT+CWJAP="ALIYUN","12345678"

[2024-05-05 10:22:09.364]
RX:WIFI CONNECTED
WIFI GOT IP

OK

[2024-05-05 10:23:16.540]
TX:AT+MQTTUSERCFG=0,1,"j07fRDwyQJM.STM32D|securemode=2\,signmethod=hmacsha256\,timestamp=1714875636112|","STM32D&j07fRDwyQJM","940229bec11687ee864a206908fcc4812bdb30873c3fecd8be8e6d234c7f6111",0,0,""

[2024-05-05 10:23:17.569]
RX:AT+MQTTUSERCFG=0,1,"j07fRDwyQJM.STM32D|securemode=2\,signmethod=hmacsha256\,timestamp=1714875636112|","STM32D&j07fRDwyQJM","940229bec11687ee864a206908fcc4812bdb30873c3fecd8be8e6d234c7f6111",0,0,""

OK

[2024-05-05 10:23:26.561]
TX:AT+MQTTCONN=0,"iot-06z00iurioijdlq.mqtt.iothub.aliyuncs.com",1883,1

[2024-05-05 10:23:27.590]
RX:AT+MQTTCONN=0,"iot-06z00iurioijdlq.mqtt.iothub.aliyuncs.com",1883,1

[2024-05-05 10:23:30.992]
RX:+MQTTCONNECTED:0,1,"iot-06z00iurioijdlq.mqtt.iothub.aliyuncs.com","1883","",1

OK

[2024-05-05 10:24:07.441]
TX:AT+MQTTSUB=0,"/sys/j07fRDwyQJM/STM32D/thing/service/property/set",0

[2024-05-05 10:24:08.473]
RX:AT+MQTTSUB=0,"/sys/j07fRDwyQJM/STM32D/thing/service/property/set",0

OK

//上行数据
[2024-05-05 10:25:40.923]
TX:AT+MQTTPUB=0,"/sys/j07fRDwyQJM/STM32D/thing/event/property/post","{\"params\":{\"temp\":35.5\}\,\"version\":\"1.0.0\"}",1,0

[2024-05-05 10:25:42.062]
RX:AT+MQTTPUB=0,"/sys/j07fRDwyQJM/STM32D/thing/event/property/post","{\"params\":{\"temp\":35.5\}\,\"version\":\"1.0.0\"}",1,0

OK

//下行数据
[2024-05-05 10:26:22.014]
RX:+MQTTSUBRECV:0,"/sys/j07fRDwyQJM/STM32D/thing/service/property/set",99,{"method":"thing.service.property.set","id":"1544868534","params":{"lighting":0},"version":"1.0.0"}

;