initial support for json rest api

pull/1/head
Thomas Ballmann 4 years ago
parent e5a382653f
commit ecdf80ac2c

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

@ -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<JsonObject>();
// ...
});
server.addHandler(handler);
server.begin();
Serial.println("setup configure - done");

Loading…
Cancel
Save