功能

主界面 UI 设计以及移植

代码

郁闷死我了

霸哥

  1. 即使如此严格地分开 client 执行也会报错,人麻了😭😭😭😭😭,这个 bug 改来改去改了三小时,为什么他程序报错但也可以执行啊😭😭😭。

    23:44了,我不管了,等它什么时候影响运行了再改吧。

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
if (weather_client.connect("api.seniverse.com", 80))
{
weather_client.print(high_low_https); // 向服务器发送HTTP请求
while (weather_client.connected() || weather_client.available())
{ // 服务器保持连接
if (weather_client.available())
{
String line = weather_client.readStringUntil('\n'); // 等待响应并且读取响应信息
Serial.println(line);
DynamicJsonDocument doc(capacity);
deserializeJson(doc, line);
JsonObject results_0_daily_0 = doc["results"][0]["daily"][0];
tem_high = results_0_daily_0["high"].as<int>(); // "33"
tem_low = results_0_daily_0["low"].as<int>(); // "21"
}
}
weather_client.stop();
}

if (weather_client.connect("api.seniverse.com", 80))
{
weather_client.print(now_https); // 向服务器发送HTTP请求
while (weather_client.connected() || weather_client.available())
{ // 服务器保持连接
if (weather_client.available())
{
String line = weather_client.readStringUntil('\n'); // 等待响应并且读取响应信息
Serial.println(line);
DynamicJsonDocument doc(capacity);
deserializeJson(doc, line);
JsonObject now = doc["results"][0]["now"];
tem_now = now["temperature"].as<int>(); // "33"
update_time = doc["results"][0]["last_update"].as<String>();
position = doc["results"][0]["location"]["name"].as<String>();
weather_condition = now["text"].as<String>();
}
}
weather_client.stop();
}

if (weather_client.connect("api.seniverse.com", 80))
{
weather_client.print(air_https); // 向服务器发送HTTP请求
while (weather_client.connected() || weather_client.available())
{ // 服务器保持连接
if (weather_client.available())
{
String line = weather_client.readStringUntil('\n'); // 等待响应并且读取响应信息
Serial.println(line);
DynamicJsonDocument doc(capacity);
deserializeJson(doc, line);
JsonObject now = doc["results"][0]["air"];
air = now["city"]["quality"].as<String>();
}
}
weather_client.stop();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
[111494][D][WiFiClient.cpp:546] connected(): Disconnected: RES: 0, ERR: 128
Date: Sun, 04 Jun 2023 15:29:54 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 388
Connection: close
access-control-allow-origin: *
etag: W/"184-c/w+MpyRWp/b7jh48Urdlg39RDs"
x-powered-by: Express
x-ratelimit-limit: 50;w=60
x-ratelimit-remaining: 46
x-ratelimit-reset: 36.851
x-request-id: F2V+YfUeIdME4uu51sLD
x-tenant-id: 1db8c05a-9790-4035-83ba-d63344b95702

最终效果

IMG_20230605_004558