diff --git a/platformio.ini b/platformio.ini index 8c4f194..0263ce2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,6 +18,7 @@ lib_deps = Adafruit GFX Library@~1.7.5 ArduinoNvs@~2.5 ESP Async WebServer@~1.2.3 + ArduinoJson@~6.14.1 # Semantic Versioning Rules # http://docs.platformio.org/page/userguide/lib/cmd_install.html#description diff --git a/src/app.cpp b/src/app.cpp index 74b15ac..5c7b2cb 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -1,6 +1,8 @@ #include "app.h" #include "SPIFFS.h" #include "ESPAsyncWebServer.h" +#include "AsyncJson.h" +#include "ArduinoJson.h" // https://techtutorialsx.com/2018/09/17/esp32-arduino-web-server-serving-external-css-file/ // https://docs.platformio.org/en/latest/platforms/espressif8266.html#uploading-files-to-file-system-spiffs @@ -27,6 +29,29 @@ void setupApp() .setCacheControl("max-age=600") ; + + // TODO response + server.on("/test", HTTP_GET, [] (AsyncWebServerRequest *request) { + AsyncResponseStream *response = request->beginResponseStream("application/json"); + + DynamicJsonDocument root(1024); + root["heap"] = ESP.getFreeHeap(); + root["ssid"] = WiFi.SSID(); + + serializeJson(root, *response); + request->send(response); + }); + + + // TODO request + AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint", [](AsyncWebServerRequest *request, JsonVariant &json) { + JsonObject jsonObj = json.to(); + + + // ... + }); + server.addHandler(handler); + server.begin(); Serial.println("setup configure - done");