ESP8266使用AT指令获取时间和心知天气

一.硬件:ESP8266,USB TO TTL模块,软件:串口调试助手

ESP8266使用AT指令获取时间和心知天气_第1张图片

二.在心知官网注册账号:心知天气 - 高精度气象数据 - 天气数据API接口 - 行业气象解决方案

三.连接esp8266和usb转ttl,打开串口调试助手

四.发送AT指令

1.复位模块

发送AT+RST

返回ready

2.测试AT指令

发送AT

返回OK

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

ESP8266使用AT指令获取时间和心知天气_第2张图片

 返回{"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"}]}ESP8266使用AT指令获取时间和心知天气_第3张图片

11.退出透传,取消发送新行

发送+++

12.禁止esp8266透传模式

发送AT+CIPMODE=0

返回OK

13.断开服务器连接

发送AT+CIPCLOSE

返回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,单片机,物联网)