Local server to get local storage measurements

This commit is contained in:
samuelbles07
2024-12-05 04:09:17 +07:00
parent bce46445d6
commit 859c1a7e92
2 changed files with 16 additions and 0 deletions

View File

@ -13,6 +13,10 @@ bool LocalServer::begin(void) {
server.on(openMetrics.getApi(), HTTP_GET, [this]() { _GET_metrics(); });
server.on("/config", HTTP_GET, [this]() { _GET_config(); });
server.on("/config", HTTP_PUT, [this]() { _PUT_config(); });
server.on("/storage", HTTP_GET, [this]() {
Serial.println(server.arg("time"));
_GET_storage();
});
server.begin();
if (xTaskCreate(
@ -68,4 +72,15 @@ void LocalServer::_GET_measure(void) {
server.send(200, "application/json", toSend);
}
void LocalServer::_GET_storage(void) {
char *data = measure.getLocalStorage();
if (data != nullptr) {
server.sendHeader("Content-Disposition", "attachment; filename=\"measurements.csv\"");
server.send(200, "text/plain", data);
free(data);
} else {
server.send(200, "text/plain", "No data");
}
}
void LocalServer::setFwMode(AgFirmwareMode fwMode) { this->fwMode = fwMode; }

View File

@ -33,6 +33,7 @@ public:
void _PUT_config(void);
void _GET_metrics(void);
void _GET_measure(void);
void _GET_storage(void);
};
#endif /** _LOCAL_SERVER_H_ */