安信可官网:
https://docs.ai-thinker.com/start
一、wifi 联网测试指令
版本:AT version: 1.2.0.0
//1.重启模块
AT+RST
//2.设置当前 Wi-Fi 模式,不保存到 flash
AT+CWMODE_CUR=1
//3.设置 DHCP,不保存到 flash
AT+CWDHCP_CUR=1,1
//4.上电是否自动连接 AP
AT+CWAUTOCONN=0
//5. 连接 AP,参数不保存到 flash
AT+CWJAP_CUR="ssid","pwd"
其它指令:
//查询版本信息
AT+GMR
如下:
[2024-07-29 01:54:47.595]
TX:AT+GMR
[2024-07-29 01:54:47.599]
RX:AT+GMR
AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK
//扫描当前可用 AP
AT+CWLAP
//查询网网络连接信息
AT+CIPSTATUS
//查询本地 IP 地址
AT+CIFSR
//断开与 AP 的连接
AT+CWQAP
二、mqtt 测试指令
//MQTT over TCP
AT+MQTTUSERCFG=0,1,"ESP32","espressif","1234567890",0,0,""
AT+MQTTCONN=0,"192.168.31.113",1883,0
AT+MQTTSUB=0,"topic",1
AT+MQTTPUB=0,"topic","test",1,0
AT+MQTTCLEAN=0
//MQTT over TLS
AT+CIPSNTPCFG=1,8,"ntp1.aliyun.com"
AT+CIPSNTPTIME?
AT+MQTTUSERCFG=0,3,"ESP32","espressif","1234567890",0,0,""
AT+MQTTCONNCFG=0,0,0,"lwtt","lwtm",0,0
AT+MQTTCONN=0,"192.168.31.113",1883,0
AT+MQTTSUB=0,"topic",1
AT+MQTTPUB=0,"topic","test",1,0
AT+MQTTCLEAN=0
//MQTT over WSS
AT+CIPSNTPCFG=1,8,"ntp1.aliyun.com"
AT+CIPSNTPTIME?
AT+MQTTUSERCFG=0,7,"ESP32","espressif","1234567890",0,0,"wss"
AT+MQTTCONN=0,"iot.eclipse.org",443,0
AT+MQTTSUB=0,"topic",1
AT+MQTTPUB=0,"topic","test",1,0
AT+MQTTCLEAN=0
测试 mqtt 相关指令,发现响应 失败,提示 ERROR。
三、解决 MQTT 指令失败
解决办法,下载相应的的固件,硬件信息如下:
3.1 固件地址
安信可固件汇总地址:
https://docs.ai-thinker.com/固件汇总
固件版本:
3.2 固件下载更新方法
烧录 wifi 固件工具下载地址:
https://docs.ai-thinker.com/开发工具2
下载过程:
1.打开软件,选择esp8266
2.选择固件,指定下载地址
3.根据自己实际需求填入 SPI SPEED、SPI MODE、COM 及 BAUD
4.可先擦除,再点击 start ,等待下载完成
详细可参考安信可文章 如何为 ESP 系列模组烧录固件
https://docs.ai-thinker.com/esp_download
查询固件信息,如下
//1.配置 MQTT 用户属性
AT+MQTTUSERCFG=0,1,"client_123","","",0,0,""
//2.设置 MQTT 连接属性
AT+MQTTCONNCFG=0,120,0,"lwt_topic","lwt_msg",0,0
//3.连接 MQTT Broker
AT+MQTTCONN=0,"8.135.10.183",26730,1
四、完整指令
安信可最新版本,版本:
AT version:2.3.0.0-dev(s-bcd64d2 - ESP8266 - Jun 23 2021 11:42:05)
SDK version:v3.4-22-g967752e2
compile time(b498b58):Jul 31 2021 11:41:32
Bin version:2.2.0(WROOM-02)
OK
完整相关指令
//1.复位
AT+RST
//1.2 上电是否自动连接 AP
AT+CWAUTOCONN=0
//2.设置参数存储模式
AT+SYSSTORE=0
//3.设置 ESP 设备的 Wi-Fi 模式
AT+CWMODE=1
//4.扫描当前可用的 AP
AT+CWLAP
//5.
//设置DHCP模式
AT+CWDHCP=1,1
或者
//设置静态ip
AT+CIPSTA="192.168.6.100","192.168.6.1","255.255.255.0"
//6.连接 wifi 设置 ESP Station 需连接的 AP
AT+CWJAP="ssid","pwd"
或者
AT+CWJAP="ssid","pwd","(mac)bssid"
//7.查询 TCP/UDP/SSL 连接状态和信息
AT+CIPSTATUS
//8.查询本地 IP 地址和 MAC 地址
AT+CIFSR
//断开与 AP 连接
AT+CWQAP
//设置 MQTT 用户属性
AT+MQTTUSERCFG=0,1,"123cli","","",0,0,""
//设置 MQTT 连接属性
AT+MQTTCONNCFG=0,120,0,"lwt_topic","lwt_msg",0,0
//连接 MQTT Broker
AT+MQTTCONN=0,"8.135.10.183",26730,0
//发布 MQTT 消息(字符串)
AT+MQTTPUB=0,"topoc","{\"testTopic1\":\"data\"}",0,0
注意:每条 AT 命令的总长度不能超过 256 字节;本命令不能发送数据 \0,若需要发送该数据,请使用AT+MQTTPUBRAW 命令。
//断开 MQTT 连接
AT+MQTTCLEAN=0
//设置时区和 SNTP 服务器
// 使能 SNTP 服务器,设置中国时区 (UTC+08:00)
AT+CIPSNTPCFG=1,8,"cn.ntp.org.cn","ntp.sjtu.edu.cn"
//查询 SNTP 时间
AT+CIPSNTPTIME?
参考:
https://docs.ai-thinker.com/media/esp8266/docs/esp8266_start_guide_1.pdf