Skip to content

Commit 3d15dcd

Browse files
committed
wip 添加农历支持
1 parent 94349bc commit 3d15dcd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/SmallDesktopDisplay.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void weaterData(String *cityDZ, String *dataSK, String *dataFC); //天气信息
9797
void refresh_AnimatedImage(); //更新右下角
9898
void log(String str); // 打印日志到串口
9999
void openWifi(); // 打开 WiFi
100+
void getLunarDate(); // 获取农历日期
100101

101102
//创建时间更新函数线程
102103
Thread reflash_time = Thread();
@@ -765,6 +766,36 @@ void saveParamCallback()
765766
}
766767
#endif
767768

769+
// 获取农历日期 FIXME 这里要么请求失败-1,如果成功则会报错重启
770+
void getLunarDate()
771+
{
772+
String URL = "https://api.zhangnew.com/v1/lunar";
773+
HTTPClient httpClient; // 创建 HTTPClient 对象
774+
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
775+
client->setInsecure(); // 因为指纹会随着证书更新而变化,这里直接忽略掉吧
776+
httpClient.begin(*client, URL); // 使用新方法
777+
int httpCode = httpClient.GET(); // 启动连接并发送HTTP请求
778+
log("正在获取农历日期");
779+
//如果服务器响应OK则从服务器获取响应体信息并通过串口输出
780+
if (httpCode == HTTP_CODE_OK)
781+
{
782+
String str = httpClient.getString();
783+
DynamicJsonDocument doc(1024);
784+
deserializeJson(doc, str);
785+
JsonObject sk = doc.as<JsonObject>();
786+
787+
String lunarDate = sk["月日"].as<String>();
788+
log("农历日期获取成功 " + lunarDate);
789+
}
790+
else
791+
{
792+
log("请求农历日期错误:", false);
793+
Serial.println(httpCode);
794+
}
795+
//关闭ESP8266与服务器连接
796+
httpClient.end();
797+
}
798+
768799
// 发送HTTP请求并且将服务器响应通过串口输出
769800
void getCityCode()
770801
{
@@ -1261,6 +1292,7 @@ void WIFI_reflash_All()
12611292

12621293
updateNtpTime();
12631294
//其他需要联网的方法写在后面
1295+
getLunarDate();
12641296

12651297
WiFi.forceSleepBegin(); // Wifi Off
12661298
log("WIFI sleep......");
@@ -1414,6 +1446,7 @@ void setup()
14141446
TJpgDec.drawJpg(15, 213, humidity, sizeof(humidity)); //湿度图标
14151447

14161448
getCityWeater();
1449+
getLunarDate();
14171450
#if DHT_EN
14181451
if (DHT_img_flag != 0)
14191452
IndoorTem();

0 commit comments

Comments
 (0)