From 7888f6432ea3d378d4fb21dbd5acb558d959e102 Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sat, 7 Mar 2020 09:57:04 +0100 Subject: [PATCH] fs improvements --- src/app.cpp | 9 ++++++--- src/download.cpp | 3 --- src/faceCalendar.cpp | 6 +----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 6f4a7f4..8421533 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -47,6 +47,10 @@ void setupApp() setupCurrentImage(); setupApiFace(); + server.onNotFound([](AsyncWebServerRequest *request) { + request->send(404); + }); + // TODO response server.on("/stats", HTTP_GET, [](AsyncWebServerRequest *request) { AsyncResponseStream *response = request->beginResponseStream("application/json"); @@ -64,11 +68,10 @@ void setupApp() doc["device"]["bootCycle"] = deviceGetBootCount(); doc["device"]["screen"]["width"] = 640; doc["device"]["screen"]["height"] = 384; - SPIFFS.begin(); + doc["device"]["fs"]["total"] = SPIFFS.totalBytes(); doc["device"]["fs"]["used"] = SPIFFS.usedBytes(); doc["device"]["fs"]["free"] = SPIFFS.totalBytes() - SPIFFS.usedBytes(); - SPIFFS.end(); doc["playlist"]["current"] = PlaylistGetCurrentFace(); doc["playlist"]["remaining"] = PlaylistGetRemainingTimeMs() / 1000; @@ -268,7 +271,7 @@ void setupApiFace() server.on("/api/face", HTTP_POST, [](AsyncWebServerRequest *request) { Serial.println("post request"); -/* + /* int params = request->params(); for (int i = 0; i < params; i++) { diff --git a/src/download.cpp b/src/download.cpp index 2419eee..4fb46bf 100644 --- a/src/download.cpp +++ b/src/download.cpp @@ -38,7 +38,6 @@ bool downloadFile(String url, const char *path) WiFiClient *stream = http.getStreamPtr(); // persist image - SPIFFS.begin(); File file = SPIFFS.open(tmpFile, FILE_WRITE); if (!file) { @@ -78,8 +77,6 @@ bool downloadFile(String url, const char *path) file.close(); SPIFFS.remove(path); SPIFFS.rename(tmpFile, path); - - SPIFFS.end(); } Serial.print("download completed in: "); diff --git a/src/faceCalendar.cpp b/src/faceCalendar.cpp index 94783a2..8ec8eb3 100644 --- a/src/faceCalendar.cpp +++ b/src/faceCalendar.cpp @@ -39,7 +39,7 @@ void showFaceCalendar() display_picture(); display_calender(); - display.nextPage(); + displayFlush(); } void downloadRandomePicture() @@ -133,8 +133,6 @@ void display_calender() void display_picture() { - SPIFFS.begin(); - File file = SPIFFS.open(faceCalendarPicture, "r"); if (!file) { @@ -152,8 +150,6 @@ void display_picture() file.close(); ImageFlushBuffer(); - - SPIFFS.end(); } void display_time()