checkpoint, switching machine. on the way to chunked response

This commit is contained in:
Torsten Ruger
2021-06-30 12:20:20 +03:00
parent e28df2e41a
commit d2eee55953
5 changed files with 71 additions and 23 deletions

View File

@ -2,9 +2,6 @@
#include "collector.hpp"
#include "serial.hpp"
#include "AsyncJson.h"
#include "ArduinoJson.h"
#include <FS.h>
#define DEBUG_OUT Serial
@ -24,29 +21,35 @@ String getContentType(String filename){
}
AsyncCallbackJsonWebHandler* weekly = new AsyncCallbackJsonWebHandler("/weekly", [](AsyncWebServerRequest *request, JsonVariant &json) {
const JsonArray& root_array = json.as<JsonArray>();
JsonArray nested = root_array.createNestedArray();
copyArray(collector.week_in , WEEK , nested);
nested = root_array.createNestedArray();
copyArray(collector.week_out , WEEK , nested);
});
AsyncCallbackJsonWebHandler* monthly = new AsyncCallbackJsonWebHandler("/monthly", [](AsyncWebServerRequest *request, JsonVariant &json) {
const JsonArray& root_array = json.as<JsonArray>();
JsonArray nested = root_array.createNestedArray();
copyArray(collector.month_in , MONTH , nested);
nested = root_array.createNestedArray();
copyArray(collector.month_out , MONTH , nested);
});
// AsyncCallbackJsonWebHandler* monthly = new AsyncCallbackJsonWebHandler("/monthly");
// monthly.onRequest( [](AsyncWebServerRequest *request, JsonVariant &json) {
// const JsonArray& root_array = json.as<JsonArray>();
// JsonArray nested = root_array.createNestedArray();
// copyArray(collector.month_in , MONTH , nested);
// nested = root_array.createNestedArray();
// copyArray(collector.month_out , MONTH , nested);
// });
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
request->send(404, "text/plain;charset=utf-8", "Not found");
}
void server_setup(){
LittleFS.begin();
server.addHandler(weekly);
server.addHandler(monthly);
server.on("/weekly", HTTP_ANY, [](AsyncWebServerRequest * request) {
DEBUG_OUT.println("weekly");
String data = collector.week_data();
request->send(200, "application/json;charset=utf-8", data);
data.clear();
});
server.on("/monthly", HTTP_ANY, [](AsyncWebServerRequest * request) {
String data = collector.month_data();
request->send(200, "application/json;charset=utf-8", data);
data.clear();
});
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
DEBUG_OUT.println("Index.html");