mirror of
https://github.com/JADE-Jerry/jcalendar.git
synced 2025-12-09 10:58:12 +08:00
1.0.25
This commit is contained in:
@@ -112,6 +112,8 @@ A: 1. 换根质量较好的或短一些的USB线,或换个USB口插入。 <br>
|
||||
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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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" // 地理位置
|
||||
|
||||
13
src/API.hpp
13
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<const char*>());
|
||||
@@ -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<const char*>());
|
||||
@@ -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<const char*>());
|
||||
@@ -254,6 +254,7 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 一言: https://developer.hitokoto.cn/sentence/
|
||||
bool getHitokoto(Hitokoto& result) {
|
||||
return getRestfulAPI("https://v1.hitokoto.cn/?max_length=15", [&result](JsonDocument& json) {
|
||||
|
||||
@@ -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 = "<br/><label for='test'>天气模式</label><br/><input type='radio' name='test' value='0' checked> 每日天气test </input><input type='radio' name='test' value='1'> 实时天气test</input>";
|
||||
// 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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user