From bd1fa3d32ddc7faf3cd4e7f130d111ad0a219e5f Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sun, 8 Mar 2020 18:10:17 +0100 Subject: [PATCH] enable update trigger over api #16 --- src/app.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 8421533..eef6f67 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,13 +1,14 @@ +#include #include "app.h" -#include "SPIFFS.h" #include "ESPAsyncWebServer.h" -//#include "AsyncJson.h" #include "ArduinoJson.h" #include "settings.h" #include "device.h" #include "playlist.h" #include "image.h" #include "display.h" +#include "faceWeather.h" +#include "faceCalendar.h" AsyncWebServer server(80); @@ -17,18 +18,13 @@ void setupWifiScan(); void setupWifiConnect(); void setupCurrentImage(); void setupApiFace(); +void setupApiUpdate(); bool updateDisplayRequired = false; void setupApp() { Serial.println("setup configure"); - if (!SPIFFS.begin()) - { - Serial.println("An Error has occurred while mounting SPIFFS"); - return; - } - // @see https://github.com/me-no-dev/ESPAsyncWebServer // @see https://arduinojson.org/v6/assistant/ @@ -46,6 +42,7 @@ void setupApp() setupWifiConnect(); setupCurrentImage(); setupApiFace(); + setupApiUpdate(); server.onNotFound([](AsyncWebServerRequest *request) { request->send(404); @@ -301,4 +298,43 @@ void setupApiFace() request->send(200, "application/ld+json; charset=utf-8", "{}"); }, handle_update_progress_cb); +} + +void setupApiUpdate() +{ + server.on("/api/update", HTTP_GET, [](AsyncWebServerRequest *request) { + int params = request->params(); + for (int i = 0; i < params; i++) + { + AsyncWebParameter *p = request->getParam(i); + if (p->isFile()) + { + Serial.printf("
  • FILE[%s]: %s, size: %u
  • ", p->name().c_str(), p->value().c_str(), p->size()); + } + else if (p->isPost()) + { + Serial.printf("
  • POST[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); + } + else + { + Serial.printf("
  • GET[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); + } + } + + if (request->hasParam("weather")) + { + Serial.println("update weather data..."); + + updateWeatherData(); + } + + if (request->hasParam("calendar")) + { + Serial.println("update calendar data..."); + + updateCalendarData(); + } + + request->send(200, "application/ld+json; charset=utf-8", "{}"); + }); } \ No newline at end of file