diff --git a/lib/app/app.cpp b/lib/app/app.cpp index 6332051..e2a9826 100644 --- a/lib/app/app.cpp +++ b/lib/app/app.cpp @@ -14,6 +14,7 @@ #include "datetime.h" #include "faceWeather.h" #include "faceCalendar.h" +#include "faceToday.h" #include "download.h" AsyncWebServer server(80); @@ -30,7 +31,7 @@ AppConfig appConfig; void setupApiDevice(); void setupApiSettings(); void setupApiWifi(); -void setupApiUpdate(); +void setupApiCache(); void setupOTA(); //flag to use from web update to update display @@ -90,7 +91,7 @@ void setupApp() setupApiDevice(); setupApiSettings(); setupApiWifi(); - setupApiUpdate(); + setupApiCache(); setupOTA(); server.onNotFound([](AsyncWebServerRequest *request) { @@ -414,11 +415,13 @@ void setupApiWifi() } /** - * api data endpoint + * api cache endpoint */ -void setupApiUpdate() +void setupApiCache() { - server.on("/api/update", HTTP_GET, [](AsyncWebServerRequest *request) { + server.on("/api/cache/clear", HTTP_GET, [](AsyncWebServerRequest *request) { + bool warmUp = request->hasParam("warmUp"); + if (request->hasParam("datetime")) { Serial.println("update datetime..."); @@ -428,26 +431,26 @@ void setupApiUpdate() if (request->hasParam("weather")) { - Serial.println("update weather data..."); + Serial.println("invalidate weather cache..."); - updateWeatherData(); + invalidFaceWeatherCache(warmUp); } if (request->hasParam("calendar")) { - Serial.println("update calendar data..."); + Serial.println("invalidate calendar cache..."); - updateCalendarData(); + invalidFaceCalendarCache(warmUp); } - if (request->getParam("url") && request->hasParam("file")) + if (request->hasParam("today")) { - Serial.println("file..."); + Serial.println("invalidate today cache..."); - downloadFile(request->getParam("url")->value().c_str(), request->getParam("file")->value().c_str()); + invalidFaceTodayCache(warmUp); } - request->send(200, "application/ld; charset=utf-8", "{}"); + request->send(200, "application/json; charset=utf-8", "{}"); }); } diff --git a/lib/download/download.cpp b/lib/download/download.cpp index 4a85fac..a8a366f 100644 --- a/lib/download/download.cpp +++ b/lib/download/download.cpp @@ -2,6 +2,7 @@ #include #include "download.h" #include "device.h" +#include "esp_task_wdt.h" bool downloadFile(String url, const char *path, const char* CAcert) { @@ -45,6 +46,9 @@ bool downloadFile(String url, const char *path, const char* CAcert) } else { + // reset watchdog, is necessary if this method is running on second cpu core + esp_task_wdt_reset(); + http.writeToStream(&file); if (file) diff --git a/lib/face/faceCalendar.cpp b/lib/face/faceCalendar.cpp index 1ad42fe..8175a7a 100644 --- a/lib/face/faceCalendar.cpp +++ b/lib/face/faceCalendar.cpp @@ -32,8 +32,7 @@ void loopFaceCalendar() if ((millis() - lastCalendarDataUpdate) >= 600000) { Serial.println(&now, "update calendar data @ %A, %B %d %Y %H:%M:%S"); - lastCalendarDataUpdate = millis(); - updateCalendarData(); + invalidFaceCalendarCache(true); } } @@ -50,12 +49,17 @@ void showFaceCalendar() displayFlush(); } -/** - * download and update calendar data - */ -bool updateCalendarData() +void invalidFaceCalendarCache(bool warmUp) { - return imageServiceUpdateFile("390x384.jpg", faceCalendarPicture); + if (warmUp) + { + imageServiceUpdateFile("390x384.jpg", faceCalendarPicture); + lastCalendarDataUpdate = millis(); + } + else + { + lastCalendarDataUpdate = 0; + } } void display_calender() diff --git a/lib/face/faceCalendar.h b/lib/face/faceCalendar.h index 4821d2c..2e46d29 100644 --- a/lib/face/faceCalendar.h +++ b/lib/face/faceCalendar.h @@ -5,6 +5,6 @@ void setupFaceCalendar(); void loopFaceCalendar(); void showFaceCalendar(); -bool updateCalendarData(); +void invalidFaceCalendarCache(bool warmUp); #endif \ No newline at end of file diff --git a/lib/face/faceToday.cpp b/lib/face/faceToday.cpp index a4b8668..90077f7 100644 --- a/lib/face/faceToday.cpp +++ b/lib/face/faceToday.cpp @@ -27,8 +27,7 @@ void loopFaceToday() if ((millis() - faceTodayUpdate) >= 600000) { Serial.println(&now, "update today data @ %A, %B %d %Y %H:%M:%S"); - faceTodayUpdate = millis(); - imageServiceUpdateFile("640x384.jpg", faceTodayPicture); + invalidFaceTodayCache(true); } } @@ -49,6 +48,19 @@ void showFaceToday() displayFlush(); } +void invalidFaceTodayCache(bool warmUp) +{ + if (warmUp) + { + imageServiceUpdateFile("640x384.jpg", faceTodayPicture); + faceTodayUpdate = millis(); + } + else + { + faceTodayUpdate = 0; + } +} + void addTodayDay() { // init @@ -90,7 +102,7 @@ void addTodayWeather() int16_t y = displayGetHeight() - 60; // add tile - canvas->fillRoundRect(x -1, y -1, 150 + 15, 60 + 15, 15, COLOR_BG); // add border + canvas->fillRoundRect(x - 1, y - 1, 150 + 15, 60 + 15, 15, COLOR_BG); // add border canvas->fillRoundRect(x, y, 150 + 15, 60 + 15, 15, COLOR_FG); // current weather condition - icon diff --git a/lib/face/faceToday.h b/lib/face/faceToday.h index 552e3c2..732ebd0 100644 --- a/lib/face/faceToday.h +++ b/lib/face/faceToday.h @@ -4,5 +4,6 @@ void setupFaceToday(); void loopFaceToday(); void showFaceToday(); +void invalidFaceTodayCache(bool warmUp); #endif \ No newline at end of file diff --git a/lib/face/faceWeather.cpp b/lib/face/faceWeather.cpp index 74cbc55..0bf55f3 100644 --- a/lib/face/faceWeather.cpp +++ b/lib/face/faceWeather.cpp @@ -20,10 +20,12 @@ void render_current(); void render_forecast(); bool readWeatherData(); bool isFaceWeatherSetupCompleted(); +bool updateWeatherData(); void setupFaceWeather() { - if (!isFaceWeatherSetupCompleted()) { + if (!isFaceWeatherSetupCompleted()) + { Serial.println("weather not configured"); } @@ -37,7 +39,6 @@ void loopFaceWeather() if ((millis() - lastWeatherDataUpdate) >= 600000) { Serial.println(&now, "update weather data @ %A, %B %d %Y %H:%M:%S"); - lastWeatherDataUpdate = millis(); updateWeatherData(); } } @@ -57,6 +58,20 @@ void showFaceWeather() displayFlush(); } +void invalidFaceWeatherCache(bool warmUp) +{ + if (warmUp) + { + updateWeatherData(); + lastWeatherDataUpdate = millis(); + } + else + { + + lastWeatherDataUpdate = 0; + } +} + bool isFaceWeatherSetupCompleted() { return !(NVS.getString("weather.api").isEmpty() || NVS.getString("weather.lang").isEmpty() || NVS.getString("weather.lang").isEmpty()); diff --git a/lib/face/faceWeather.h b/lib/face/faceWeather.h index dd8e83f..65303ee 100644 --- a/lib/face/faceWeather.h +++ b/lib/face/faceWeather.h @@ -38,7 +38,6 @@ extern faceWeatherData weatherData; void setupFaceWeather(); void loopFaceWeather(); void showFaceWeather(); - -bool updateWeatherData(); +void invalidFaceWeatherCache(bool warmUp); #endif \ No newline at end of file