-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek_weather.ino
63 lines (58 loc) · 2.05 KB
/
week_weather.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <M5EPD.h>
#include "EPDWifi.h"
#include "Config.h"
#include <HTTPClient.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
void Get_Week_Weather_Data()
{
if (WiFi.status() == WL_CONNECTED) // Check WiFi connection status
{
HTTPClient http; // Declare an object of class HTTPClient
// specify request destination
http.begin(OPENWEATHER_URL_WEEK); // !!
int httpCode = http.GET(); // send the request
if (httpCode > 0) // check the returning code
{
String res = http.getString(); // Get the request response payload
DynamicJsonDocument root(5120);
// Parse JSON object
deserializeJson(root, res);
auto error = deserializeJson(root, res);
if (error)
{
Serial.print(F("deserializeJson() failed with code "));
Serial.println(error.c_str());
return;
}
Serial.println("--------------");
// print data
int x_start = 40;
int y_start = 270;
int x_text_start = 90;
int y_text_start = 390;
int x_offset = 130;
for (int i = 0; i < 7; i++) {
String weather_icon = root["list"][i]["weather"][0]["icon"];
float temp_min = root["list"][i]["temp"]["min"];
float temp_max = root["list"][i]["temp"]["max"];
char strtemp_min[10] = "";
dtostrf(temp_min, 2, 0, strtemp_min);
char strtemp_max[10] = "";
dtostrf(temp_max, 2, 0, strtemp_max);
String icon_path = "/weather2/" + weather_icon + ".png";
int str_len = icon_path.length() + 1;
char char_array[str_len];
icon_path.toCharArray(char_array, str_len);
canvas.drawPngFile(SD, char_array, x_start, y_start);
canvas.createRender(30, 256);
canvas.setTextSize(30);
canvas.setTextDatum(TC_DATUM);
canvas.drawString(strtemp_min + String("°-") + strtemp_max + String("°"), x_text_start, y_text_start);
x_start += x_offset;
x_text_start += x_offset;
}
}
http.end(); // Close connection
}
}