checkpoint, switching machine. on the way to chunked response
This commit is contained in:
@ -97,3 +97,43 @@ void Collector::add_month(int from){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String Collector::one_week(float week[]){
|
||||
String data = "[";
|
||||
data += String(week[0] , 1) ;
|
||||
for( int a = 1; a < WEEK ; a += 1 ) {
|
||||
data += "," ;
|
||||
data += String(week[a] , 1) ;
|
||||
}
|
||||
data += "]";
|
||||
return data ;
|
||||
}
|
||||
|
||||
String Collector::week_data(){
|
||||
String data = "[";
|
||||
data += one_week(week_in) ;
|
||||
data += "," ;
|
||||
// data += one_week(week_out) ;
|
||||
// data += "]";
|
||||
return data;
|
||||
}
|
||||
|
||||
String Collector::one_month(float month[]){
|
||||
String data = "[";
|
||||
data += String(month[0] , 1);
|
||||
for( int a = 1; a < MONTH ; a += 1 ) {
|
||||
data += "," ;
|
||||
data += String(month[a], 1) ;
|
||||
}
|
||||
data += "]";
|
||||
return data ;
|
||||
}
|
||||
|
||||
String Collector::month_data(){
|
||||
String data = "[";
|
||||
data += one_month(month_in) ;
|
||||
// data += "," ;
|
||||
// data += one_month(month_out) ;
|
||||
data += "]";
|
||||
return data ;
|
||||
}
|
@ -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");
|
||||
|
Reference in New Issue
Block a user