一.硬件:ESP8266,USB TO TTL模块,软件:串口调试助手
二.在心知官网注册账号:心知天气 - 高精度气象数据 - 天气数据API接口 - 行业气象解决方案
三.连接esp8266和usb转ttl,打开串口调试助手
四.发送AT指令
1.复位模块
发送AT+RST
返回ready
2.测试AT指令
发送AT
返回OK文章来源地址https://www.toymoban.com/news/detail-439994.html
3.配置STA模式
发送AT+CWMODE=1
返回OK
4.连接wifi
发送AT+CWJAP="wifi名称","wifi密码"
返回OK
5.设置时间地域
发送AT+CIPSNTPCFG=1,8
返回OK
6.获取时间
发送AT+CIPSNTPTIME?
返回+CIPSNTPTIME:Fri Jul 22 17:33:39 2022
OK
7.连接心知服务器
发送AT+CIPSTART="TCP","api.seniverse.com",80
返回OK
8.使能esp8266透传模式
发送AT+CIPMODE=1 //0:禁止 1:使能
返回OK
9.开启数据传输
发送AT+CIPSEND
返回OK
10.获取天气信息(私钥,城市,语言)
发送GET https://api.seniverse.com/v3/weather/now.json?key=ScuqSTA5ihQt3Oyhf&location=chengdu&language=zh-Hans&unit=c
返回{"results":[{"location":{"id":"WM6N2PM3WY2K","name":"成都","country":"CN","path":"成都,成都,四川,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"阴","code":"9","temperature":"20"},"last_update":"2022-09-26T10:50:12+08:00"}]}
11.退出透传,取消发送新行
发送+++
12.禁止esp8266透传模式
发送AT+CIPMODE=0
返回OK
13.断开服务器连接
发送AT+CIPCLOSE文章来源:https://www.toymoban.com/news/detail-439994.html
返回OK
五.以下为串口调试助手调试记录
AT+RST
OK
WIFI DISCONNECT
rd l | l < $ #| r b c go l'o cp l;d;dp ' lco | | c o' d l` o'd`n; ۓo d`p ' ; bo | c 'g l` ngl` g{ ' x g { #n < $l c 'o l og d '{ 'Û { gÓ
################################################
arch:ESP8266, 1
compile_time:Ai-Thinker|B&T
wifi_mac:e098068a38E7
sdk_version:v3.4-22-g967752e2
firmware_version:2.2.0
compile_time:Jun 30 2021 11:28:20
ready
################################################WIFI CONNECTED
WIFI GOT IP
AT
OK
AT+CWMODE=1
OK
AT+CWJAP="SZT","18190815525"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP
OK
AT+CIPSTART="TCP","api.seniverse.com",80
CONNECT
OK
AT+CIPMODE=1
OK
AT+CIPSEND
OK
>{"results":[{"location":{"id":"WM6N2PM3WY2K","name":"成都","country":"CN","path":"成都,成都,四川,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"阴","code":"9","temperature":"20"},"last_update":"2022-09-26T10:50:12+08:00"}]}{"results":[{"location":{"id":"WM6N2PM3WY2K","name":"成都","country":"CN","path":"成都,成都,四川,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"阴","code":"9","temperature":"20"},"last_update":"2022-09-26T10:50:12+08:00"}]}AT+CIPMODE=0
OK
AT+CIPCLOSE
CLOSED
OK
到了这里,关于ESP8266使用AT指令获取时间和心知天气的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!