-
大小: 3.14MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-11-20
- 语言: 其他
- 标签:
资源简介
ESP8266+OLED屏实现天气预报+温度显示+NTP时间同步5屏带中文显示改进版,天气采用和风V7版API获取,解决天气显示异常的问题。
代码片段和文件信息
#include
#include
#include
#include
#include “HeFeng.h“
HeFeng::HeFeng() {
}
void HeFeng::doUpdateCurr(HeFengCurrentData *data String key String location) { //获取天气
std::unique_ptrclient(new BearSSL::WiFiClientSecure);
client->setInsecure();//不带校验
HTTPClient https;
//String url = “https://free-api.heweather.net/s6/weather/now?lang=en&location=“ + location + “&key=“ + key;//S6版本
String url = “https://devapi.qweather.com/v7/weather/now?lang=en&location=“ + location + “&key=“ + key + “&gzip=n“;//V7版本
Serial.print(“[HTTPS] begin...now\n“); //[HTTPS] begin...now
if (https.begin(*client url)) {
// 启动连接并发送http头
int httpCode = https.GET();
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf(“[HTTPS] GET... code: %d\n“ httpCode); //[HTTPS] GET... code: 200
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
// Serial.println(https.getString());
String json = https.getString();
Serial.println(json); //打印json数据
DynamicJsonDocument doc(780);
deserializeJson(doc json);
// Jsonobject root = doc.asject>();
Jsonobject root = doc[“now“];
//String now_temp = root[“now“][“temp“];
String now_temp = root[“temp“];
data->tmp = now_temp;
Serial.println(now_temp);
//String now_feelsLike = root[“now“][“feelsLike“];
String now_feelsLike = root[“feelsLike“];
Serial.println(now_feelsLike);
data->fl = now_feelsLike;
//String now_humidity = root[“now“][“humidity“];
String now_humidity = root[“humidity“];
Serial.println(now_humidity);
data->hum = now_humidity;
// String now_windScale = doc[“now“][“windScale“];
String now_windScale = root[“windScale“];
data->wind_sc = now_windScale;
//String now_icon = root[“now“][“icon“];
String now_icon = root[“icon“];
Serial.println(now_icon);
String meteoconIcon = getMeteoconIcon(now_icon);
// String now_text = root[“now“][“text“];
String now_text = root[“text“];
Serial.println(now_text);
data->cond_txt = now_text;
data->iconMeteoCon = meteoconIcon;
}
} else {
Serial.printf(“[HTTPS] GET... failed error: %s\n“ https.errorToString(httpCode).c_str());
data->tmp = “-1“;
data->fl = “-1“;
data->hum = “-1“;
data->wind_sc = “-1“;
data->cond_txt = “no network“;
data->iconMeteoCon = “)“;
}
https.end();
} else {
Serial.printf(“[HTTPS] Unable to connect\n“);
data->tmp = “-1“;
data->fl = “-1“;
data->hum = “-1“;
data->wind_sc = “-1“;
data->cond_txt = “no network“;
dat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 270 2020-07-20 04:33 weather_clock_ntp5V7\.gitignore
文件 30651 2020-12-28 12:04 weather_clock_ntp5V7\Esp8266_Clock_Weather\Esp8266_Clock_Weather.ino
文件 7780 2020-12-28 13:00 weather_clock_ntp5V7\Esp8266_Clock_Weather\HeFeng.cpp
文件 616 2020-12-27 18:04 weather_clock_ntp5V7\Esp8266_Clock_Weather\HeFeng.h
文件 112356 2020-07-20 04:33 weather_clock_ntp5V7\Esp8266_Clock_Weather\WeatherStationFonts.h
文件 26819 2020-07-20 04:33 weather_clock_ntp5V7\Esp8266_Clock_Weather\WeatherStationImages.h
文件 1069 2020-07-20 04:33 weather_clock_ntp5V7\LICENSE
文件 2991 2020-07-20 04:33 weather_clock_ntp5V7\README.md
文件 130 2002-05-11 12:05 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\ASC.PTL
文件 18092 2002-05-15 15:31 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\Gb2312.PTL
文件 2122 2002-05-12 00:14 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\notice.txt
文件 310272 2002-05-11 19:53 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\PCtoLCD2002.exe
文件 407 2020-12-26 09:40 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\PCtoLCD2002.INI
文件 4427 2002-05-12 00:13 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\readme2002.txt
文件 676352 2002-02-01 22:00 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\RTL60.BPL
文件 1326080 2002-02-01 22:00 weather_clock_ntp5V7\取模软件\pctolcd2002\PCtoLCD2002\VCL60.BPL
文件 74 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\取模软件信息.txt
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\1.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\2.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\3.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\4.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\5.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\6.c
文件 2670 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\7.c
文件 24813 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2).gif
文件 8101 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2)_1.jpeg
文件 8603 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2)_2.jpeg
文件 8233 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2)_3.jpeg
文件 8694 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2)_4.jpeg
文件 8899 2020-07-20 04:33 weather_clock_ntp5V7\取模软件\小电视动画1\xiaodianshi(2)_5.jpeg
............此处省略48个文件信息
评论
共有 条评论