#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 "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", "{}");
});
}

@ -2,6 +2,7 @@
#include <SPIFFS.h>
#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)

@ -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()

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

@ -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

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

@ -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());

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