ESP8266 AT MQTT-TCP 透传指令TLS加密接入阿里云物联网平台笔记;

一、简介

前面为大家带来的是无加密的AT MQTT直连阿里云物联网平台的笔记,链接为:

https://blog.csdn.net/Boantong_/article/details/104791452

在这里插入图片描述
上述提到,推荐使用TLS加密直连!
今天,给大家带来的是如何在这基础之上TLS加密连接,安全性更高!

二、准备材料

  • ESP-12S模组一个;
  • AT MQTT固件阿里云物联网专有固件:已经加入阿里云根证书: 点我下载

烧录截图:
在这里插入图片描述

三、指令说明

至于在阿里云物联网后台新建一个产品,如何生成连接MQTT的参数,这里不再累赘!下面只说关键的AT说明!

  • AT+CWMODE=1设置为 station 模式!

  • AT+CWJAP="iot@xuhongv","12345678"连接路由器!

  • AT+MQTTUSERCFG=0,3,"ClientId","userName","password",0,0,"" 配置连接参数,第2个参数为3,表示本地校验服务器域名证书!如果是1则表示无校验!

  • AT+MQTTCONN=0,"xxxxx.iot-as-mqtt.cn-shanghai.aliyuncs.com",1883,1 设置域名,开始连接!


AT固件支持多种加密形式传输,上面我们只用到了非双向认证,只用到了本地校验服务器,也就是第二个参数为3!

1: MQTT over TCP 
2: MQTT over TLS(no certificate verify)
3: MQTT over TLS(verify server certificate)
4: MQTT over TLS(provide client certificate)
5: MQTT over TLS(verify server certificate and provide client certificate)
6: MQTT over WebSocket(based on TCP)
7: MQTT over WebSocket Secure(based on TLS, no certificate verify)
8: MQTT over WebSocket Secure(based on TLS, verify server certificate)
9: MQTT over WebSocket Secure(based on TLS, provide client certificate)
10: MQTT over WebSocket Secure(based on TLS, verify server certificate and provide client certificate) 

所以,整个交互过程:

ready
AT+CWMODE=1

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

OK
AT+CWJAP="iot@xuhongv","xuhong12345678"
WIFI CONNECTED
WIFI GOT IP

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

OK
AT+MQTTUSERCFG=0,3,"123|securemode=2\,signmethod=hmacsha1\,timestamp=20190725|","CA01-01&a1PcEbO4qmU","B7FDC3D825C1C271544B0ECD11D846484236C018",0,0,""

OK
AT+MQTTCONN=0,"a1PcEbO4qmU.iot-as-mqtt.cn-shanghai.aliyuncs.com",1883,1
+MQTTCONNECTED:0,3,"a1PcEbO4qmU.iot-as-mqtt.cn-shanghai.aliyuncs.com","1883","",1

OK

  • 共勉~联系:support@aithinker.com