diff --git a/README.md b/README.md
index 8c138fa..6916e29 100644
--- a/README.md
+++ b/README.md
@@ -112,6 +112,8 @@ A: 1. 换根质量较好的或短一些的USB线,或换个USB口插入。
A: 仅刷新app固件后,配置是保留的,所以,无需重新配置。如果刷新了分区表partition.bin,会将esp的nvs区刷新,这时候需要重新配置。
## Releases
+### 1.0.25 (未测试)
+* Fix: 和风天气api变更,需要输入API Host(在配置页面增加配置项)
### 1.0.24
* Refine: 配置页面location约束改为64长度,允许输入经纬度设置天气位置(e.g. 116.41,39.92)
### 1.0.23
diff --git a/dist/jcalendar_1.0.24_z15.bin b/dist/jcalendar_1.0.25_z15.bin
similarity index 72%
rename from dist/jcalendar_1.0.24_z15.bin
rename to dist/jcalendar_1.0.25_z15.bin
index 918b82c..72171c8 100644
Binary files a/dist/jcalendar_1.0.24_z15.bin and b/dist/jcalendar_1.0.25_z15.bin differ
diff --git a/dist/jcalendar_1.0.24_z21.bin b/dist/jcalendar_1.0.25_z21.bin
similarity index 72%
rename from dist/jcalendar_1.0.24_z21.bin
rename to dist/jcalendar_1.0.25_z21.bin
index a5d3e9f..771816a 100644
Binary files a/dist/jcalendar_1.0.24_z21.bin and b/dist/jcalendar_1.0.25_z21.bin differ
diff --git a/dist/jcalendar_1.0.24_z98.bin b/dist/jcalendar_1.0.25_z98.bin
similarity index 76%
rename from dist/jcalendar_1.0.24_z98.bin
rename to dist/jcalendar_1.0.25_z98.bin
index ac571f2..e863040 100644
Binary files a/dist/jcalendar_1.0.24_z98.bin and b/dist/jcalendar_1.0.25_z98.bin differ
diff --git a/include/_preference.h b/include/_preference.h
index caf1ef0..0755db7 100644
--- a/include/_preference.h
+++ b/include/_preference.h
@@ -8,6 +8,7 @@
// !!!preferences key限制15字符
#define PREF_SI_CAL_DATE "SI_CAL_DATE" // 屏幕当前显示的日期
#define PREF_SI_WEEK_1ST "SI_WEEK_1ST" // 每周第一天,0: 周日(默认),1:周一
+#define PREF_QWEATHER_HOST "QWEATHER_HOST" // QWEATHER HOST
#define PREF_QWEATHER_KEY "QWEATHER_KEY" // QWEATHER KEY/TOKEN
#define PREF_QWEATHER_TYPE "QWEATHER_TYPE" // 0: 每日天气,1: 实时天气
#define PREF_QWEATHER_LOC "QWEATHER_LOC" // 地理位置
diff --git a/src/API.hpp b/src/API.hpp
index c64072b..cd482b8 100755
--- a/src/API.hpp
+++ b/src/API.hpp
@@ -163,10 +163,10 @@ public:
}
// 和风天气 - 实时天气: https://dev.qweather.com/docs/api/weather/weather-now/
- bool getWeatherNow(Weather& result, const char* key, const char* locid) {
+ bool getWeatherNow(Weather& result, const char* host, const char* key, const char* locid) {
// return getRestfulAPI("https://www.baidu.com", [&result](JsonDocument& json) {
return getRestfulAPI(
- "https://api.qweather.com/v7/weather/now?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
+ "https://" + String(host) + "/v7/weather/now?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
if (strcmp(json["code"], "200") != 0) {
Serial.print(F("Get weather failed, error: "));
Serial.println(json["code"].as());
@@ -188,8 +188,8 @@ public:
}
// 和风天气 - 逐小时天气预报: https://dev.qweather.com/docs/api/weather/weather-hourly-forecast/
- bool getForecastHourly(HourlyForecast& result, const char* key, const char* locid) {
- return getRestfulAPI("https://api.qweather.com/v7/weather/24h?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
+ bool getForecastHourly(HourlyForecast& result, const char* host, const char* key, const char* locid) {
+ return getRestfulAPI("https://" + String(host) + "/v7/weather/24h?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
if (strcmp(json["code"], "200") != 0) {
Serial.print(F("Get hourly forecast failed, error: "));
Serial.println(json["code"].as());
@@ -216,8 +216,8 @@ public:
}
// 和风天气 - 逐天天气预报: https://dev.qweather.com/docs/api/weather/weather-daily-forecast/
- bool getForecastDaily(DailyForecast& result, const char* key, const char* locid) {
- return getRestfulAPI("https://api.qweather.com/v7/weather/3d?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
+ bool getForecastDaily(DailyForecast& result, const char* host, const char* key, const char* locid) {
+ return getRestfulAPI("https://" + String(host) + "/v7/weather/3d?key=" + String(key) + "&location=" + String(locid), [&result](JsonDocument& json) {
if (strcmp(json["code"], "200") != 0) {
Serial.print(F("Get daily forecast failed, error: "));
Serial.println(json["code"].as());
@@ -253,6 +253,7 @@ public:
return true;
});
}
+
// 一言: https://developer.hitokoto.cn/sentence/
bool getHitokoto(Hitokoto& result) {
diff --git a/src/main.cpp b/src/main.cpp
index 726ad3c..3dfd86b 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,11 +21,12 @@ void IRAM_ATTR checkTicks() {
}
WiFiManager wm;
-WiFiManagerParameter para_qweather_key("qweather_key", "和风天气Token", "", 32); // 和风天气key
+WiFiManagerParameter para_qweather_host("qweather_host", "和风天气Host", "", 64); // 和风天气key
+WiFiManagerParameter para_qweather_key("qweather_key", "和风天气API Key", "", 32); // 和风天气key
// const char* test_html = "
每日天气test 实时天气test";
// WiFiManagerParameter para_test(test_html);
WiFiManagerParameter para_qweather_type("qweather_type", "天气类型(0:每日天气,1:实时天气)", "0", 2, "pattern='\\[0-1]{1}'"); // 城市code
-WiFiManagerParameter para_qweather_location("qweather_loc", "位置ID", "", 9, "pattern='\\d{9}'"); // 城市code
+WiFiManagerParameter para_qweather_location("qweather_loc", "位置ID", "", 64); // 城市code
WiFiManagerParameter para_cd_day_label("cd_day_label", "倒数日(4字以内)", "", 10); // 倒数日
WiFiManagerParameter para_cd_day_date("cd_day_date", "日期(yyyyMMdd)", "", 8, "pattern='\\d{8}'"); // 城市code
WiFiManagerParameter para_tag_days("tag_days", "日期Tag(yyyyMMddx,详见README)", "", 30); // 日期Tag
@@ -187,6 +188,7 @@ void buttonClick(void* oneButton) {
void saveParamsCallback() {
Preferences pref;
pref.begin(PREF_NAMESPACE);
+ pref.putString(PREF_QWEATHER_HOST, para_qweather_host.getValue());
pref.putString(PREF_QWEATHER_KEY, para_qweather_key.getValue());
pref.putString(PREF_QWEATHER_TYPE, strcmp(para_qweather_type.getValue(), "1") == 0 ? "1" : "0");
pref.putString(PREF_QWEATHER_LOC, para_qweather_location.getValue());
@@ -222,6 +224,7 @@ void buttonDoubleClick(void* oneButton) {
// 根据配置信息设置默认值
Preferences pref;
pref.begin(PREF_NAMESPACE);
+ String qHost = pref.getString(PREF_QWEATHER_HOST);
String qToken = pref.getString(PREF_QWEATHER_KEY);
String qType = pref.getString(PREF_QWEATHER_TYPE, "0");
String qLoc = pref.getString(PREF_QWEATHER_LOC);
@@ -231,6 +234,7 @@ void buttonDoubleClick(void* oneButton) {
String week1st = pref.getString(PREF_SI_WEEK_1ST, "0");
pref.end();
+ para_qweather_host.setValue(qHost.c_str(), 64);
para_qweather_key.setValue(qToken.c_str(), 32);
para_qweather_location.setValue(qLoc.c_str(), 64);
para_qweather_type.setValue(qType.c_str(), 1);
@@ -241,6 +245,7 @@ void buttonDoubleClick(void* oneButton) {
wm.setTitle("J-Calendar");
wm.addParameter(¶_si_week_1st);
+ wm.addParameter(¶_qweather_host);
wm.addParameter(¶_qweather_key);
wm.addParameter(¶_qweather_type);
wm.addParameter(¶_qweather_location);
diff --git a/src/weather.cpp b/src/weather.cpp
index 15f71dd..c2c815e 100644
--- a/src/weather.cpp
+++ b/src/weather.cpp
@@ -4,6 +4,7 @@
TaskHandle_t WEATHER_HANDLER;
+String _qweather_host;
String _qweather_key;
String _qweather_loc;
@@ -45,9 +46,9 @@ void task_weather(void* param) {
// 实时天气
bool success;
if (_weather_type == 0) {
- success = api.getForecastDaily(_daily_forecast, _qweather_key.c_str(), _qweather_loc.c_str());
+ success = api.getForecastDaily(_daily_forecast, _qweather_host.c_str(), _qweather_key.c_str(), _qweather_loc.c_str());
} else {
- success = api.getWeatherNow(_weather_now, _qweather_key.c_str(), _qweather_loc.c_str());
+ success = api.getWeatherNow(_weather_now, _qweather_host.c_str(), _qweather_key.c_str(), _qweather_loc.c_str());
}
if (success) {
_weather_status = 1;
@@ -74,6 +75,7 @@ void weather_exec(int status) {
// Preference 获取配置信息。
Preferences pref;
pref.begin(PREF_NAMESPACE);
+ _qweather_host = pref.getString(PREF_QWEATHER_HOST, "api.qweather.com");
_qweather_key = pref.getString(PREF_QWEATHER_KEY, "");
_qweather_loc = pref.getString(PREF_QWEATHER_LOC, "");
pref.end();