当前位置: 代码迷 >> 综合 >> 【掌控板-arduino】7.2 联网获取天气
  详细解决方案

【掌控板-arduino】7.2 联网获取天气

热度:71   发布时间:2023-12-05 20:32:48.0

文章目录

  • 0 前言
  • 1 心知获取api
  • 2 问题
  • 3 使用httpclient
  • 4 代码
  • 5 现象
  • 6 不足

0 前言

参考文章
Arduino ESP32通过心知天气获取城市三天的信息
利用ESP8266+OLED(I2C)打造智能时钟(网络校时+实时天气+天气预报)
ESP8266+0.96寸OLED+心知天气制作天气时钟

(重点)玩转 ESP32 + Arduino (十四) HTTPClient库访问网络资源

使用Arduino开发ESP32(20):使用HTTPClient访问HTTP服务器

1 心知获取api

注册账户
添加产品
在这里插入图片描述
添加完成后,选中免费版,可以查看到私钥
在这里插入图片描述
测试接口
https://api.seniverse.com/v3/weather/now.json?key=XXXXXX&location=suzhou&language=zh-Hans&unit=c
在这里插入图片描述
英文
https://api.seniverse.com/v3/weather/now.json?key=XXXXXX&location=suzhou&language=en&unit=c
在这里插入图片描述

2 问题

我查了arduino sdk lib,在wificlient.cpp中没有找到print函数,可能在其他路径下。
在这里插入图片描述

int WiFiClient::available() {
    if (_sock != 255){
    return ServerDrv::availData(_sock);}return 0;
}class WiFiClient : public Client {
    
public:WiFiClient();WiFiClient(uint8_t sock);
}

3 使用httpclient

参考文章:玩转 ESP32 + Arduino (十四) HTTPClient库访问网络资源

本文代码是参考的上述文章,使用的库是HTTPClient,代码路径如下:
C:\Users\XXX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\HTTPClient\src

PS:arduino有三大代码路径

  1. C:\Users\XXX\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\HTTPClient\src(硬件相关驱动)
  2. D:\arduino_sdk\arduino-nightly-windows\arduino-nightly\libraries(arduino平台驱动)
  3. C:\Users\XXX\Documents\Arduino\libraries(通过arduino的管理库下载的代码都在这里)

本次使用的就是硬件驱动文件夹下的HTTPClient。
在arduino_sdk下有HttpClient.c,注意文件名大小区分。
HTTPClient的相关用法可以参见:使用Arduino开发ESP32(20):使用HTTPClient访问HTTP服务器

4 代码

如果只需要获取天气状态,则可以先参见这篇文章:玩转 ESP32 + Arduino (十四) HTTPClient库访问网络资源。
如下代码是在太空人代码基础上添加了天气查询。

复制如下代码需要进行几处修改:

  1. 修改wifi账户和密码
  2. 填写私钥,方法参见前文
  3. 显示模块的接线需要和硬件匹配
//----------------------------------------
// func: get weather from https://api.seniverse.com
// defect: use http to get weather will cost 0.897s, which will result to animation stop.
// so, get weather will be place in enter patterns.
//
//----------------------------------------
#include <Arduino.h>
#include <WiFi.h>
#include "HTTPClient.h"
#define DEBUG_WIFI 1String data_time_date = "2022-1-12";  // year-month-day
String data_time_clock = "12:17:20"; // hour-min-sec
String data_time_week = "Wednesday";  // week
String data_weather = "晴";  // weather// xinzhi weather api
// from: https://blog.csdn.net/qq_46595907/article/details/121277454?spm=1001.2014.3001.5501
const char* host = "https://api.seniverse.com";
const char* ipaddress = "116.62.81.138";
const int httpPort = 80;
String location = "suzhou";
String private_key = "XXXXXXXX";	//需要获取私钥
String weather = "";
String url = "";    // send command
// delay 5s due to api request time 20/min
int temp_delaytime=0;
String weather_data = "sunny";// client 2 ---- fail
WiFiClient client;
//const char* host = "api.seniverse.com";
void send_http_request2()
{
    if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");return;}String url = "/v3/weather/daily.json?key="+private_key+"&location="+location+"&language=en&unit=c";Serial.print("Requesting URL: ");Serial.println(url);// client.print(String("GET ") + url + " HTTP/1.1\r\n" +
// "Host: " + host + "\r\n" +
// "Connection: close\r\n\r\n"); client.println("https://api.seniverse.com"+url);while (client.available()) {
    String line = client.readStringUntil('\r');weather_data += line;}client.stop();Serial.println();Serial.println("closing connection");    Serial.println();Serial.println(weather_data);}// client 1 ---- ok
WiFiClient wifi_client;
HTTPClient http_client;
//HttpClient http_client;
String req;   //request command
String rsp;   //resultvoid set_weather()
{
    
// if (temp_delaytime == 49)
// {
    
// send_http_request2();send_http_request();get_weather();
// }
}void send_http_request()
{
    req = (String)host + "/v3/weather/now.json?key=";req += private_key;req += "&location=";req += location;req += "&language=en&unit=c";
// Serial.println(req);if (http_client.begin(req)){
    Serial.println("HTTPclient setUp done!");}
// Serial.println(weather_data);}//json to weather_data
void get_weather_data()
{
    
// Serial.println("weather_data:");
// Serial.println(weather_data);// api data format// {"results":[// {"location":// {"id":"WTTDPCGXTWUS","name":"Suzhou",// "country":"CN","path":"Suzhou,Suzhou,Jiangsu,China",// "timezone":"Asia/Shanghai","timezone_offset":"+08:00"},// "now":{"text":"Overcast","code":"9","temperature":"7"},// "last_update":"2022-01-15T19:04:13+08:00"}]}// need to get "Overcast"String temp_substring1 = "text";String temp_substring2 = "code";int temp_start = rsp.indexOf(temp_substring1)+7;int temp_end = rsp.indexOf(temp_substring2)-3;
// Serial.print(temp_start);
// Serial.print("\t");
// Serial.println(temp_end);weather_data = rsp.substring(temp_start, temp_end);Serial.println(weather_data);
}void get_weather()
{
    int http_code = http_client.GET();
// Serial.println(http_code);if (http_code > 0){
    
// Serial.printf("HTTP get code: %d\n", http_code);if (http_code == HTTP_CODE_OK){
    rsp = http_client.getString();
// Serial.println(rsp);}else{
    Serial.printf("fail to get cityWeather,code:%d\n", http_code);delay(100);get_weather();}}//json to weather_dataget_weather_data();
}// wifi -- get time
//https://www.arduino.cn/thread-93795-1-1.html
//https://blog.csdn.net/DWX_top/article/details/120650278#define NTP1 "ntp1.aliyun.com"
#define NTP2 "ntp2.aliyun.com"
#define NTP3 "ntp3.aliyun.com"const char *ssid = "LangZhao";         
const char *password = "19971226";     const String WDAY_NAMES[] = {
    "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; //星期
const String WDAY_NAMES_CHAR[] = {
    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //星期
const String MONTH_NAMES[] = {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; //月份// patter0 watch display
#include "watch_bmp.h"
int watch_image_current = 0;   // save now display image number
#define WATCH_IMAGE_NUM 4
const uint8_t * watch_image_addr[WATCH_IMAGE_NUM]={
    Watch_Image1,Watch_Image2,Watch_Image3,Watch_Image4};// display
#include "SH1106Wire.h"
SH1106Wire display(0x3c, 23, 22);   void setClock()
{
    
// Serial.println("enter setclock");struct tm timeInfo; if (!getLocalTime(&timeInfo)){
     //一定要加这个条件判断,否则内存溢出Serial.println("Failed to obtain time");return;}//Serial.print(asctime(&timeInfo)); //默认打印格式:Mon Oct 25 11:13:29 2021String date = WDAY_NAMES[timeInfo.tm_wday];data_time_date = String(timeInfo.tm_year + 1900); //yeardata_time_date += "-";if(timeInfo.tm_mon < 10)data_time_date += "0";data_time_date += timeInfo.tm_mon + 1; //monthdata_time_date += "-";if(timeInfo.tm_mday < 10)data_time_date += "0";data_time_date += timeInfo.tm_mday; //dayif(timeInfo.tm_hour < 10)data_time_clock += "0";data_time_clock = String(timeInfo.tm_hour); //hourdata_time_clock += ":";if(timeInfo.tm_min < 10)data_time_clock += "0";data_time_clock += timeInfo.tm_min; //mindata_time_clock += ":";if(timeInfo.tm_sec < 10)data_time_clock += "0";data_time_clock += timeInfo.tm_sec; //secdata_time_week = WDAY_NAMES_CHAR[timeInfo.tm_wday]; //week// Serial.print("data_time_date:");
// Serial.println(data_time_date);
// Serial.print("data_time_clock:");
// Serial.println(data_time_clock);
// Serial.print("data_time_week:");
// Serial.println(data_time_week);
}void display_time()
{
    
#if DEBUG_WIFIsetClock();
#endifdisplay.drawString(64,0,data_time_date);display.drawString(64,16,data_time_clock);display.drawString(64,32,data_time_week);
// display.display();
}void display_weather()
{
    // weather chinese
// display.drawXbm(64,48,32,16,WEATHER2);// weather englishdisplay.drawString(64,48,weather_data);// display.display();
}void drawImageDemo_64_64_w(int picture_num) {
    // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html// on how to create xbm filesif(picture_num <0 || picture_num > 3){
    Serial.println("error picture_num");picture_num = 0;}  display.drawXbm(0, 0, Watch_Image_width, Watch_Image_height, watch_image_addr[picture_num]);
}void display_bmp_watch(){
    
// display.clear();drawImageDemo_64_64_w(watch_image_current);
// display.display();
}void wifi_init()
{
    //设置ESP32工作模式为无线终端模式WiFi.mode(WIFI_STA);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED){
    delay(500);Serial.print(".");}Serial.println("WiFi connected!");Serial.println("before configtime");configTime(8 * 3600, 0, NTP1, NTP2, NTP3);Serial.println("after configtime!");// display.clear();
// display.drawString(0,0,"WiFi connected!");
// display.display();
// delay(3000);
}//enter pattern1(weather/time) 
void pattern_solution1()
{
      //display watch imageif (watch_image_current < WATCH_IMAGE_NUM -1 )watch_image_current++;else watch_image_current=0;// Serial.println("start set_weather");
// set_weather();
// Serial.println("end set_weather");display.clear();
// Serial.println("start pict");display_bmp_watch();
// Serial.println("end pict");display_time();display_weather();display.display();//display 4 picture delay timedelay(100);// //move to setup
// if (temp_delaytime < 50)
// temp_delaytime ++;
// else
// temp_delaytime = 0;
}void setup() {
    Serial.begin(115200);Serial.println("enter setup");// connect wifi
#if DEBUG_WIFIwifi_init();
#endif// init displaydisplay.init();display.flipScreenVertically();display.setFont(ArialMT_Plain_10);set_weather();Serial.println("exit setup");
}void loop() {
    pattern_solution1();
}
//watch_bmp.h
#define Watch_Image_width 64
#define Watch_Image_height 64
const uint8_t Watch_Image1[] PROGMEM = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x7F,0x0C,0x00,0x00,0x00,0x00,0x00,0x1E,0xFE,0x1D,0x00,0x00,0x00,0x00,0x00,0x0E,0xDE,0x19,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x33,0x00,0x00,0x00,0x00,0x80,0x03,0xC0,0xB3,0x01,0x00,0x00,0x00,0x80,0x01,0x80,0xE7,0x73,0x00,0x00,0x00,0xC0,0x01,0x80,0xC7,0x70,0x00,0x00,0x00,0xC0,0x00,0x80,0xCF,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x9E,0x01,0x00,0x00,0x00,0xE0,0x00,0x00,0x1E,0x03,0x00,0x00,0x00,0xE0,0x00,0x00,0x1C,0x03,0x18,0x00,0x00,0x60,0x00,0x00,0x18,0x06,0x3C,0x00,0x00,0xE0,0x00,0x00,0x18,0x04,0x3C,0x00,0x00,0xE0,0x01,0x00,0x18,0x0C,0x38,0x00,0x00,0xC0,0x01,0x00,0x18,0x18,0x00,0x00,0x00,0xC0,0x01,0x00,0x18,0x10,0x00,0x00,0x00,0xC0,0x03,0x00,0x0C,0x00,0x00,0x00,0x00,0x80,0x03,0x00,0x1C,0x00,0x18,0x00,0x00,0x80,0x03,0x00,0x3E,0x00,0x18,0x00,0x00,0x00,0x03,0x00,0x77,0x00,0x10,0x00,0x00,0x00,0x07,0x80,0xE7,0x00,0x00,0x00,0x00,0x00,0x1E,0xE0,0xDF,0x00,0x00,0x00,0x00,0x00,0xFC,0xFC,0x9E,0x01,0x00,0x00,0x00,0x00,0xE0,0x3F,0x36,0x03,0x00,0x00,0x00,0x00,0x00,0x1F,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x06,0xF8,0x07,0x60,0x00,0x00,0x00,0x00,0x06,0xF8,0x0C,0x00,0x00,0x00,0x00,0x00,0x0C,0xF8,0x0C,0x00,0x00,0x00,0x00,0x00,0x1C,0xF0,0x1E,0x00,0x00,0x00,0x00,0x00,0x18,0xE0,0x37,0x00,0x00,0x00,0x00,0x00,0x18,0x60,0x27,0x00,0x00,0x00,0x00,0x00,0x30,0x38,0x04,0x00,0x00,0x00,0x00,0x00,0x20,0x3C,0x0C,0x00,0x00,0x00,0x0C,0x00,0x60,0x3E,0x08,0x00,0x00,0x00,0x0C,0x00,0xE0,0x77,0x0C,0x00,0x00,0x00,0x0C,0x00,0xC0,0xE7,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x9C,0x37,0x00,0x00,0x00,0x00,0x80,0x01,0xF0,0x39,0x06,0x00,0x00,0x00,0x80,0x03,0xE0,0x1F,0x06,0x00,0x00,0x00,0x00,0x03,0xE0,0x0F,0x04,0x00,0x00,0x80,0x01,0x06,0xC0,0x03,0x00,0x00,0x00,0x00,0x00,0x0E,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0xC0,0x00,0x00,0x00,0x00,0xC0,0x30,0x60,0x80,0x01,0x00,0x00,0x00,0xC0,0x71,0xE0,0x80,0x01,0x00,0x00,0x00,0x00,0x61,0xC0,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
};
const uint8_t Watch_Image2[] 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,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3E,0x02,0x1E,0x00,0x00,0x00,0x00,0x07,0x70,0x0E,0x0E,0x00,0x00,0x00,0x80,0x03,0xE0,0x0C,0x0E,0x00,0x00,0x00,0xC0,0x03,0x80,0x19,0x18,0x00,0x00,0x00,0xC0,0x01,0x80,0x33,0x00,0x00,0x00,0x00,0xEC,0x01,0x00,0x33,0x00,0x00,0x00,0x00,0xE6,0x00,0x00,0x22,0x00,0x00,0x00,0x00,0x66,0x00,0x00,0x66,0x00,0x06,0x00,0x00,0xF6,0x1F,0x00,0xC6,0x00,0x06,0x00,0x00,0xF6,0x7F,0x00,0xC7,0x01,0x06,0x00,0x00,0xF6,0xFF,0x00,0x87,0x01,0x00,0x00,0x00,0xF6,0xFF,0x01,0x06,0x03,0x00,0x00,0x00,0xF6,0xFF,0x01,0x06,0x06,0x01,0x00,0x00,0xE6,0xFF,0x03,0x06,0x86,0x03,0x00,0x00,0xE6,0xFF,0x07,0x0E,0x04,0x01,0x00,0x00,0xE6,0xFF,0x07,0x1F,0x00,0x00,0x00,0x00,0xC0,0xFF,0x07,0x33,0x00,0x00,0x00,0x00,0xC0,0xFF,0x87,0x2F,0x00,0x00,0x00,0x00,0x80,0xFF,0xC7,0x3D,0x00,0x00,0x00,0x30,0x00,0xFF,0xE7,0x78,0x00,0x00,0x00,0x60,0x00,0xFF,0x77,0xE0,0x00,0x0C,0x00,0x40,0x00,0xFC,0x3F,0xC3,0x01,0x1C,0x00,0x70,0x00,0xF8,0x0F,0xCF,0x01,0x1C,0x00,0x00,0x00,0x00,0x06,0xFC,0x03,0x1C,0x00,0x00,0x00,0x00,0x0E,0x78,0x03,0x00,0x00,0x00,0x00,0x00,0x0C,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x0C,0xE3,0x01,0x00,0x00,0x00,0x00,0x00,0x9C,0xC7,0x03,0x00,0x00,0x00,0x00,0x00,0xD8,0x66,0x03,0x00,0x00,0x00,0x00,0x00,0xB8,0x3F,0x06,0x00,0x00,0x80,0x01,0x00,0x30,0x1B,0x06,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0xF0,0x03,0x06,0x06,0x00,0x00,0x00,0x00,0xC0,0x31,0x0F,0x0C,0x00,0x00,0x00,0x00,0x80,0xF3,0x1B,0x0C,0x00,0x00,0x00,0x80,0x00,0xE6,0x0D,0x00,0x00,0x00,0x00,0x80,0x01,0xFC,0x07,0x00,0x00,0x00,0x00,0x00,0x03,0xF8,0x03,0x01,0x00,0x00,0x00,0x00,0x06,0xF0,0x01,0x03,0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x03,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const uint8_t Watch_Image3[] 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,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0xFE,0x9F,0x03,0x00,0x00,0x00,0x00,0x00,0x3F,0x1C,0x60,0x00,0x00,0x00,0x00,0x80,0x0F,0x70,0x70,0x00,0x00,0x00,0x00,0xC0,0x00,0xC0,0x70,0x00,0x00,0x00,0x00,0x40,0xF8,0xC0,0x61,0x0C,0x00,0x00,0x00,0x60,0xFE,0x83,0x01,0x04,0x00,0x00,0x00,0x20,0xFF,0x87,0x03,0x00,0x00,0x00,0x00,0xB0,0xFF,0x8F,0x03,0x00,0x00,0x00,0x00,0xB0,0xFF,0x1F,0x03,0x80,0x00,0x00,0x00,0xF0,0xFF,0x1F,0x03,0x80,0x00,0x00,0x00,0xD0,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0xF0,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0xF0,0xFF,0x3F,0x03,0x00,0x00,0x00,0x00,0xF0,0xFF,0xBF,0x03,0x00,0x00,0x00,0x00,0xE0,0xFF,0xBF,0x07,0x00,0x00,0x00,0x00,0xE0,0xFF,0xBF,0x0F,0x40,0x00,0x00,0x00,0xE0,0xFF,0xDF,0x1D,0x40,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x30,0x00,0x00,0x00,0x00,0xB0,0xFF,0x3F,0x66,0x00,0x00,0x00,0x00,0x30,0xFF,0x3F,0xCE,0x00,0x0C,0x00,0x00,0x60,0xFE,0x0F,0xDC,0x01,0x08,0x00,0x00,0xC0,0xF8,0x07,0x70,0x0F,0x00,0x00,0x00,0xC0,0x80,0x01,0x3C,0x1E,0x00,0x00,0x00,0x80,0x01,0x03,0xFE,0x1B,0x00,0x00,0x00,0x00,0x03,0x03,0xD2,0x19,0x00,0x00,0x00,0x00,0x03,0x07,0xDE,0x30,0x00,0x00,0x00,0x00,0x06,0x77,0xFC,0x61,0x00,0x00,0x80,0x00,0x06,0xFF,0x20,0xE1,0x00,0x00,0x80,0x01,0x0C,0xDE,0x01,0x41,0x00,0x00,0x00,0x00,0x18,0xFC,0x02,0x01,0x00,0x00,0x00,0x00,0x18,0xFC,0x13,0x0B,0x00,0x00,0x00,0x00,0x10,0xFC,0xB1,0x1F,0x00,0x00,0x00,0xE0,0x00,0xD0,0xF3,0x35,0x00,0x00,0x00,0xA0,0x00,0x00,0x77,0x36,0x00,0x00,0x00,0xE0,0x00,0x00,0xFC,0x03,0x00,0x00,0x00,0xC0,0x00,0x00,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x80,0x79,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x33,0x30,0x00,0x00,0x00,0x04,0x00,0x00,0x03,0x30,0x00,0x00,0x00,0x0C,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
const uint8_t Watch_Image4[] PROGMEM = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x7F,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x70,0x00,0x00,0x00,0x00,0x00,0xE0,0xC3,0x38,0x00,0x00,0x00,0x00,0x00,0xFC,0x8F,0x6B,0x00,0x00,0x00,0x00,0x00,0x3E,0x1F,0x03,0x00,0x00,0x00,0x00,0x80,0x9F,0x7F,0x06,0x00,0x00,0x00,0x00,0xC0,0xC7,0xFF,0x04,0x00,0x00,0x00,0x00,0xC0,0xE3,0xFF,0x00,0x00,0x00,0x00,0x00,0xE0,0xE3,0xFF,0x01,0x00,0x00,0x00,0x00,0x60,0xF0,0xFF,0x01,0x00,0x00,0x00,0x00,0x70,0xF0,0xFF,0x83,0x01,0x00,0x00,0x00,0x30,0xF0,0xFF,0x83,0x01,0x00,0x00,0x00,0x30,0xF0,0xFF,0x83,0x01,0x00,0x00,0x00,0x30,0xF0,0xFF,0x03,0x00,0x00,0x00,0x00,0x30,0xF0,0xFF,0x03,0x00,0x00,0x00,0x00,0x30,0xF0,0xFF,0x03,0x00,0x00,0x00,0x00,0x30,0xF0,0xFF,0x03,0x00,0x00,0x00,0x00,0x30,0xE0,0xFF,0x03,0x00,0x00,0x00,0x00,0x30,0xE0,0xFF,0x03,0x00,0x00,0x00,0x00,0x70,0xC0,0xFF,0x03,0x10,0x00,0x00,0x00,0x60,0x80,0xFF,0x07,0x10,0x00,0x00,0x00,0xC0,0x01,0xFE,0x1E,0x00,0x00,0x00,0x00,0xC0,0x03,0xE0,0x1C,0x00,0x00,0x00,0x30,0x80,0x37,0x70,0x3C,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0xF8,0x00,0x38,0x00,0x00,0x00,0xF8,0x0F,0xE0,0x01,0x38,0x00,0x00,0x00,0x00,0x03,0xE0,0x01,0x18,0x00,0x00,0xC0,0x00,0x1B,0xE0,0x01,0x20,0x00,0x10,0xC0,0x01,0x1B,0xE7,0x03,0x00,0x00,0x00,0x80,0x01,0x1B,0xCF,0x07,0x00,0x00,0x00,0x80,0x03,0x9B,0xCD,0x07,0x00,0x00,0x00,0x00,0x02,0x33,0xEF,0x01,0x00,0x00,0x00,0x00,0x0C,0x76,0x06,0x01,0x00,0x00,0x00,0x00,0x0C,0x7E,0x00,0x03,0x00,0x00,0x00,0x00,0x08,0x7E,0x62,0x03,0xE0,0x00,0x00,0x00,0x30,0xEC,0xE1,0x03,0x60,0x00,0x00,0x01,0x30,0xFC,0xC1,0x07,0x60,0x00,0x00,0x00,0x60,0xB8,0xE1,0x07,0xC0,0x00,0x00,0x00,0xE0,0x00,0xF3,0x07,0xC0,0x00,0x00,0x80,0xC3,0x00,0xBE,0x01,0x80,0x01,0x00,0xC0,0xC3,0x00,0xDC,0x00,0x00,0x01,0x00,0xC6,0x83,0x01,0xF8,0x00,0x00,0x00,0x00,0xC4,0x02,0xC1,0x38,0x00,0x04,0x00,0x00,0x00,0x03,0x80,0x01,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};//晴天
const uint8_t WEATHER1[] PROGMEM = {
    0x00,0x04,0x00,0x04,0xDE,0x7F,0x12,0x04,0x92,0x3F,0x12,0x04,0xD2,0x7F,0x1E,0x00,0x92,0x3F,0x92,0x20,0x92,0x3F,0x92,0x20,0x9E,0x3F,0x92,0x20,0x80,0x28,0x80,0x10,
};//多云
const uint8_t WEATHER2[] PROGMEM = {
    0x40,0x00, 0x00,0x00,0x40,0x00, 0xFC,0x1F,0xE0,0x0F, 0x00,0x00,0x10,0x04, 0x00,0x00,0x1C,0x02, 0x00,0x00,0x20,0x01, 0x00,0x00,0xC0,0x02, 0xFF,0x7F,0x30,0x01, 0x40,0x00,0x8E,0x1F, 0x20,0x00,0x40,0x10, 0x20,0x00,0x30,0x08, 0x10,0x02,0x4C,0x04, 0x08,0x04,0x80,0x02, 0x04,0x08,0x80,0x01, 0xFE,0x1F,0x70,0x00, 0x04,0x10,0x0E,0x00, 0x00,0x10,/*"多",0*/  /*"云",1*/
/* (16 X 16 , 宋体 )*/
};//阴天
const uint8_t WEATHER3[] PROGMEM = {
    0x00,0x00,0xBE,0x3F,0xA2,0x20,0x92,0x20,0x92,0x20,0x8A,0x3F,0x92,0x20,0x92,0x20,0xA2,0x20,0xA2,0x3F,0xA2,0x20,0x96,0x20,0x4A,0x20,0x42,0x20,0x22,0x28,0x12,0x10,/*"阴",0*/};//雨
const uint8_t WEATHER4[] PROGMEM = {
    0x00,0x00,0xFF,0x7F,0x80,0x00,0x80,0x00,0x80,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,0x92,0x22,0xA2,0x24,0x82,0x20,0x92,0x22,0xA2,0x24,0x82,0x20,0x82,0x28,0x02,0x10,/*"雨",0*/
};//霾
const uint8_t WEATHER5[] PROGMEM = {
    0xFC,0x1F,0x80,0x00,0xFE,0x7F,0x82,0x40,0xB9,0x2E,0x0C,0x00,0xD3,0x3F,0xB4,0x24,0x8C,0x3F,0x93,0x24,0xA8,0x3F,0x26,0x04,0xB0,0x3F,0x2C,0x04,0xA3,0x7F,0x18,0x00,/*"霾",0*/};const uint8_t Watch_EMPTY[] 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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};

5 现象

在这里插入图片描述
后续有空再把天气的英文转换为中文。

6 不足

由于获取时间需要向服务器发送命令,再获取结果,目前测试下来时间大概是0.897s,如果在显示太空人动图时执行该函数,则出现肉眼可见的暂停,目前没有找到什么好的方法将其穿插进显示中,只好在放在显示动画之前。
如果有什么好的方法,欢迎一起讨论。

  相关解决方案