ESP8266+0.96寸OLED+心知天气制作天气时钟

news/2024/11/16 18:55:36/

天气时钟的制作

  • 一.准备
    • 代码
      • 演示效果

一.准备

我的天气时钟的制作是基于太极创客制作的<ESP8266_Seniverse.h>和网上天气时钟项目进行开发。

Nodemcu开发板
在这里插入图片描述

中景园0.96寸OLED(七线制SPI)

GND - GND
VCC - 3.3V
D0 - D2
D1 - D1
RES - D7
DC - D5
CS - D6

在这里插入图片描述

面包板
在这里插入图片描述

杜邦线
在这里插入图片描述

代码

#include <ESP8266WiFi.h>
#include <ESP8266_Seniverse.h>
#include <U8g2lib.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <WiFiManager.h>U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 4, /* data=*/ 5, /* cs=*/ 12, /* dc=*/ 14, /* reset=*/ 13);/*DI   ------ D1 D0  ------- D2 DC  ------- D5 CS  ------- D6 RES -------D7*/// weather
const String weathers[] = {"晴", "晴", "晴", "晴", "多云", "晴间多云", "晴间多云", "大部多云", "大部多云", "阴","阵雨", "雷阵雨", "雷雨冰雹", "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨","冻雨", "雨夹雪", "阵雪", "小雪", "中雪", "大雪", "暴雪", "浮尘", "扬沙", "沙尘暴","强沙暴", "雾", "霾", "风", "大风", "飓风", "热带风暴", "龙卷风", "冷", "热", "未知"};const String test[] = {"","",""};
static const unsigned char qintian[] PROGMEM =
{
//晴,天
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x00,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F,0xFF,0x0F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,
0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0xFC,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x0F,0x00,0x00,
0x00,0x80,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x3F,0x00,0x00,0x00,
0x00,0x00,0x80,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char yintian[] PROGMEM =
{
//阴,天0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0xFF,0x00,0x00,0x00,0x00,
0xF0,0x01,0xF8,0xFF,0xFF,0x01,0x00,0x00,0x00,0xFC,0x0F,0xFC,0xFF,0xFF,0x03,0x00,0x00,0x00,0xFE,0x1F,0xFE,0xFF,0xFF,0x03,0x00,0x00,0x00,0xFF,0x3F,0xFE,0xFF,0xFF,
0x07,0x00,0x00,0x80,0xFF,0x7F,0xFF,0xFF,0xFF,0x07,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xE0,0xFF,
0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,
0x00,0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xFE,0xFF,0xFF,
0xFF,0xFF,0xFF,0x3F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0xC0,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x0F,0x00,0x00,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (70 X 60 )*/};
static const unsigned char duoyun[] PROGMEM =
{
//多,云
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x07,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0x03,0x00,
0x00,0x00,0x00,0xF8,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x1F,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x3F,0x00,
0x00,0x00,0x80,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0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00,
0xC0,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char xiaoyu[] PROGMEM =
{
//小,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x3F,0x00,0x00,
0x00,0x00,0x00,0xE0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x0F,0xF0,0xFF,0xFF,0x00,0x00,0x00,0xC0,0x7F,0xF8,0xFF,0xFF,0x01,0x00,0x00,0xF0,0xFF,0xF8,0xFF,0xFF,0x03,0x00,
0x00,0xF8,0xFF,0xFD,0xFF,0xFF,0x03,0x00,0x00,0xF8,0xFF,0xFF,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,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char zhongyu[] PROGMEM =
{
//中,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x1F,0x00,0x00,
0x00,0x00,0x00,0xC0,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x00,0x00,0x00,0x80,0x1F,0xF0,0xFF,0xFF,0x01,0x00,0x00,0xE0,0x3F,0xF8,0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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0x87,0x07,0x00,0x00,0x00,
0x00,0x00,0x80,0x87,0x07,0x00,0x00,0x00,0x00,0x00,0x80,0x03,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (60 X 60 )*/
};
static const unsigned char dayu[] PROGMEM =
{
//大,雨
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0x03,0x00,0x00,
0x00,0x00,0x00,0xF0,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0xF8,0xFF,0x1F,0x00,0x00,0x00,0x80,0x03,0xFC,0xFF,0x3F,0x00,0x00,0x00,0xF0,0x1F,0xFE,0xFF,0x3F,0x00,0x00,
0x00,0xFC,0x3F,0xFE,0xFF,0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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x04,0x00,0x00,0x00,
0x00,0x00,0x30,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x1E,0x00,0x00,0x00,
0x00,0x00,0x38,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* (60 X 60 )*/
};
typedef struct
{int zuigaowendu;int zuidiwendu;int shidu;int tianqitubiao;
}tianqixinxi; //最高温最低温和湿度和天气现象代码的结构体
tianqixinxi day1,day2,day3;int OnTime = 0; //显示变量const char* ssid     = "***";       // 连接WiFi名
const char* password = "***";          // 连接WiFi密码
String reqUserKey = "***";// 私钥
String reqLocation = "***";// 城市
String reqUnit = "c";// 摄氏/华氏WeatherNow weatherNow;
Forecast forecast;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp1.aliyun.com", 60 * 60 * 8, 30 * 60 * 1000);void connectWiFi(); //函数声明
void DisplayTianqi();
void DisplayTime();
void Get_weather();void setup() {Serial.begin(115200);u8g2.begin();u8g2.enableUTF8Print();u8g2.clearBuffer();u8g2.sendBuffer();delay(850);connectWiFi();// 配置心知天气请求信息weatherNow.config(reqUserKey, reqLocation, reqUnit);forecast.config(reqUserKey, reqLocation, reqUnit);timeClient.begin();
}void loop() {u8g2.clearBuffer();// 清空显示设备内部缓冲区u8g2.setFont(u8g2_font_wqy12_t_gb2312);DisplayTianqi();  //函数调用DisplayTime();Get_weather();u8g2.sendBuffer();// 显示缓冲区内容delay(10000);
}void display_tq(int dday,int tq,int dw,int gw,int sd)
{switch(dday)  //显示今明后天{case 0:u8g2.setCursor(85, 15);  //设置光标位置u8g2.print("今天");break;  case 1:u8g2.setCursor(85, 15);u8g2.print("明天");break;case 2:u8g2.setCursor(85, 15);u8g2.print("后天");break;}    switch(tq)  //显示天气图片{case 0:u8g2.drawXBMP( 0 , 0 , 60 , 60, qintian );break;case 4:u8g2.drawXBMP( 0 , 0 , 60 , 60, duoyun );break;case 9:u8g2.drawXBMP( 0 , 0 , 70 , 60, yintian );break;case 13:u8g2.drawXBMP( 0 , 0 , 60 , 60, xiaoyu );break;case 14:u8g2.drawXBMP( 0 , 0 , 60 , 60, zhongyu );break;case 15:u8g2.drawXBMP( 0 , 0 , 60 , 60, dayu );break;}u8g2.setCursor(90,30);String str3 = weathers[tq];  //显示天气(中文)u8g2.print(str3);u8g2.setCursor(70, 45);String str1 = test[0] + dw + "-" + gw + "℃"; //显示最低温度到最高温度u8g2.print(str1);u8g2.setCursor(70, 60);u8g2.print("湿度:");u8g2.setCursor(100, 60);String str2 = test[1] + sd + "%";  //显示湿度u8g2.print(str2);
}  void DisplayZZXS(int dday)
{switch(dday){case 0:display_tq(dday,day1.tianqitubiao,day1.zuidiwendu,day1.zuigaowendu,day1.shidu);break;  case 1:display_tq(dday,day2.tianqitubiao,day2.zuidiwendu,day2.zuigaowendu,day2.shidu);break;  case 2:display_tq(dday,day3.tianqitubiao,day3.zuidiwendu,day3.zuigaowendu,day3.shidu);break;  }
}void DisplayTianqi()
{if(OnTime > 1){DisplayZZXS(OnTime-2);//Serial.println("打印天气中");  }
}void Get_weather()
{if (millis()> 5000 && forecast.update()) { // 每五秒获取一次天气数据{day1.tianqitubiao = forecast.getDayCode(0);day1.zuigaowendu = forecast.getHigh(0);day1.zuidiwendu = forecast.getLow(0);day1.shidu =  forecast.getHumidity(0);day2.tianqitubiao = forecast.getDayCode(1);day2.zuigaowendu = forecast.getHigh(1);day2.zuidiwendu = forecast.getLow(1);day2.shidu =  forecast.getHumidity(1);day3.tianqitubiao = forecast.getDayCode(2);day3.zuigaowendu = forecast.getHigh(2);day3.zuidiwendu = forecast.getLow(2);day3.shidu =  forecast.getHumidity(2);OnTime++;   //显示标志位 0,1,2显示时间 3显示今天天气 4显示明天天气 5显示后天天气OnTime%=5;    }}
}void DisplayTime()
{u8g2.setFont(u8g2_font_wqy16_t_gb2312);if(OnTime ==0 or OnTime == 1){u8g2.setCursor(55, 30);u8g2.print("深圳");if (timeClient.update()) {u8g2.setCursor(50, 50);String time = timeClient.getFormattedTime().substring(0, 5);u8g2.print(time);}}
}// 连接WiFi
void connectWiFi() {// 建立WiFiManager对象WiFiManager wifiManager;// 自动连接WiFi。以下语句的参数是连接ESP8266时的WiFi名称wifiManager.autoConnect("AutoConnectAP");
}

演示效果

链接: link.
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


http://www.ppmy.cn/news/201754.html

相关文章

天气预报模块

目录 步骤1. 选择 API2. 发送网络请求3. 接收网络响应获得的json并进行解析4. 天气图标的显示 QT 界面设计 步骤 1. 选择 API 我用的是 聚合数据 上的 “天气预报” https://www.juhe.cn/docs/api/id/73 选择它的原因主要是&#xff1a;免费、数据简洁明了 2. 发送网络请求…

Python天气预报查询

功能&#xff1a; 实现城市天气预报查询&#xff0c;并提供未来四天查询 两个网站接口&#xff0c;直接返回数据&#xff0c;之后对数据进行读取和处理&#xff0c;很简单的小程序 效果图&#xff1a; 代码实现&#xff1a; import urllib.request import gzip import json…

酷睿i7 12800hx和i7 12800H区别

i7 12800H采用 14 核心 20 线程&#xff0c;应该是由 6 大核心 8 小核心组成&#xff0c;主频 2.8GHz&#xff0c;24MB 三级缓存&#xff0c;在 GeekBench 5 中单核心 1654 分&#xff0c;多核心 9618 分 笔记本cpu选i7 12800H还是i7 12800hx这些点很重要 http://www.adiannao.…

Qt 天气

写了一个简单的显示天气信息的例子。 其中涉及到http&#xff0c; xml&#xff0c; c11 天气信息是用webxml接口获取的&#xff0c;包括图片素材。 通过getSupportProvince获取支持的省份信息&#xff0c;getSupportCity获取当前省份中的城市&#xff0c;getWeatherbyCityNam…

网易(weather)天气预报接口

请求链接&#xff1a; http://weather.mail.163.com/weather/xhr/weather/info.do?sid&uid&host&verjs6&fontfaceyahei&style1&skinseablue&color&city101100410&callback00 参数&#xff1a; city 城市编号 返回结果&#xff1a; {&qu…

【空间天气】空间天气预报

文章目录 1.预报要素与时效2.太阳活动预报3.行星际天气预报4.磁层天气预报5.电离层天气预报6.中高层大气天气预报7.预报方法和预报检验8.空间天气机构和预报能力9.目前的主要预报业务模式9.目前的主要预报业务模式 1.预报要素与时效 空间天气预报水平主要取决于空间天气监测能力…

利用 Python 得到未来七天天气预报

因为自己平时都不看手机上的天气 app&#xff0c;因此都是出门之后“冷暖自知”&#xff0c;而在秦皇岛晚上总是会被冻得瑟瑟发抖&#xff0c;因此想写一个小脚本可以查询未来几天的天气&#xff0c;让自己选择合适的衣服。 经过查询&#xff0c;选择中国天气网 &#xff0c;里…

【读书笔记】《平凡的世界》- 路遥

他又进一步想&#xff0c;郝红梅抛开他而和顾养民相好&#xff0c;也完全是正常的啊&#xff01;他自己在哪方面都无法和顾养民比较。男女相好&#xff0c;这是两厢情愿的事&#xff0c;而怎能像乡俗话说的“剃头担子一头热”呢&#xff1f; 青春激流打起的第一个浪头在内心渐渐…