#55 cache clear and warm up implemented

pull/1/head
Thomas Ballmann 3 years ago
parent f3a933a508
commit a9a84dd06e

@ -14,6 +14,7 @@
#include "datetime.h" #include "datetime.h"
#include "faceWeather.h" #include "faceWeather.h"
#include "faceCalendar.h" #include "faceCalendar.h"
#include "faceToday.h"
#include "download.h" #include "download.h"
AsyncWebServer server(80); AsyncWebServer server(80);
@ -30,7 +31,7 @@ AppConfig appConfig;
void setupApiDevice(); void setupApiDevice();
void setupApiSettings(); void setupApiSettings();
void setupApiWifi(); void setupApiWifi();
void setupApiUpdate(); void setupApiCache();
void setupOTA(); void setupOTA();
//flag to use from web update to update display //flag to use from web update to update display
@ -90,7 +91,7 @@ void setupApp()
setupApiDevice(); setupApiDevice();
setupApiSettings(); setupApiSettings();
setupApiWifi(); setupApiWifi();
setupApiUpdate(); setupApiCache();
setupOTA(); setupOTA();
server.onNotFound([](AsyncWebServerRequest *request) { 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")) if (request->hasParam("datetime"))
{ {
Serial.println("update datetime..."); Serial.println("update datetime...");
@ -428,26 +431,26 @@ void setupApiUpdate()
if (request->hasParam("weather")) if (request->hasParam("weather"))
{ {
Serial.println("update weather data..."); Serial.println("invalidate weather cache...");
updateWeatherData(); invalidFaceWeatherCache(warmUp);
} }
if (request->hasParam("calendar")) 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", "{}");
}); });
} }

@ -2,6 +2,7 @@
#include <SPIFFS.h> #include <SPIFFS.h>
#include "download.h" #include "download.h"
#include "device.h" #include "device.h"
#include "esp_task_wdt.h"
bool downloadFile(String url, const char *path, const char* CAcert) 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 else
{ {
// reset watchdog, is necessary if this method is running on second cpu core
esp_task_wdt_reset();
http.writeToStream(&file); http.writeToStream(&file);
if (file) if (file)

@ -32,8 +32,7 @@ void loopFaceCalendar()
if ((millis() - lastCalendarDataUpdate) >= 600000) if ((millis() - lastCalendarDataUpdate) >= 600000)
{ {
Serial.println(&now, "update calendar data @ %A, %B %d %Y %H:%M:%S"); Serial.println(&now, "update calendar data @ %A, %B %d %Y %H:%M:%S");
lastCalendarDataUpdate = millis(); invalidFaceCalendarCache(true);
updateCalendarData();
} }
} }
@ -50,12 +49,17 @@ void showFaceCalendar()
displayFlush(); displayFlush();
} }
/** void invalidFaceCalendarCache(bool warmUp)
* download and update calendar data
*/
bool updateCalendarData()
{ {
return imageServiceUpdateFile("390x384.jpg", faceCalendarPicture); if (warmUp)
{
imageServiceUpdateFile("390x384.jpg", faceCalendarPicture);
lastCalendarDataUpdate = millis();
}
else
{
lastCalendarDataUpdate = 0;
}
} }
void display_calender() void display_calender()

@ -5,6 +5,6 @@
void setupFaceCalendar(); void setupFaceCalendar();
void loopFaceCalendar(); void loopFaceCalendar();
void showFaceCalendar(); void showFaceCalendar();
bool updateCalendarData(); void invalidFaceCalendarCache(bool warmUp);
#endif #endif

@ -27,8 +27,7 @@ void loopFaceToday()
if ((millis() - faceTodayUpdate) >= 600000) if ((millis() - faceTodayUpdate) >= 600000)
{ {
Serial.println(&now, "update today data @ %A, %B %d %Y %H:%M:%S"); Serial.println(&now, "update today data @ %A, %B %d %Y %H:%M:%S");
faceTodayUpdate = millis(); invalidFaceTodayCache(true);
imageServiceUpdateFile("640x384.jpg", faceTodayPicture);
} }
} }
@ -49,6 +48,19 @@ void showFaceToday()
displayFlush(); displayFlush();
} }
void invalidFaceTodayCache(bool warmUp)
{
if (warmUp)
{
imageServiceUpdateFile("640x384.jpg", faceTodayPicture);
faceTodayUpdate = millis();
}
else
{
faceTodayUpdate = 0;
}
}
void addTodayDay() void addTodayDay()
{ {
// init // init
@ -90,7 +102,7 @@ void addTodayWeather()
int16_t y = displayGetHeight() - 60; int16_t y = displayGetHeight() - 60;
// add tile // 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); canvas->fillRoundRect(x, y, 150 + 15, 60 + 15, 15, COLOR_FG);
// current weather condition - icon // current weather condition - icon

@ -4,5 +4,6 @@
void setupFaceToday(); void setupFaceToday();
void loopFaceToday(); void loopFaceToday();
void showFaceToday(); void showFaceToday();
void invalidFaceTodayCache(bool warmUp);
#endif #endif

@ -20,10 +20,12 @@ void render_current();
void render_forecast(); void render_forecast();
bool readWeatherData(); bool readWeatherData();
bool isFaceWeatherSetupCompleted(); bool isFaceWeatherSetupCompleted();
bool updateWeatherData();
void setupFaceWeather() void setupFaceWeather()
{ {
if (!isFaceWeatherSetupCompleted()) { if (!isFaceWeatherSetupCompleted())
{
Serial.println("weather not configured"); Serial.println("weather not configured");
} }
@ -37,7 +39,6 @@ void loopFaceWeather()
if ((millis() - lastWeatherDataUpdate) >= 600000) if ((millis() - lastWeatherDataUpdate) >= 600000)
{ {
Serial.println(&now, "update weather data @ %A, %B %d %Y %H:%M:%S"); Serial.println(&now, "update weather data @ %A, %B %d %Y %H:%M:%S");
lastWeatherDataUpdate = millis();
updateWeatherData(); updateWeatherData();
} }
} }
@ -57,6 +58,20 @@ void showFaceWeather()
displayFlush(); displayFlush();
} }
void invalidFaceWeatherCache(bool warmUp)
{
if (warmUp)
{
updateWeatherData();
lastWeatherDataUpdate = millis();
}
else
{
lastWeatherDataUpdate = 0;
}
}
bool isFaceWeatherSetupCompleted() bool isFaceWeatherSetupCompleted()
{ {
return !(NVS.getString("weather.api").isEmpty() || NVS.getString("weather.lang").isEmpty() || NVS.getString("weather.lang").isEmpty()); return !(NVS.getString("weather.api").isEmpty() || NVS.getString("weather.lang").isEmpty() || NVS.getString("weather.lang").isEmpty());

@ -38,7 +38,6 @@ extern faceWeatherData weatherData;
void setupFaceWeather(); void setupFaceWeather();
void loopFaceWeather(); void loopFaceWeather();
void showFaceWeather(); void showFaceWeather();
void invalidFaceWeatherCache(bool warmUp);
bool updateWeatherData();
#endif #endif
Loading…
Cancel
Save