Added restart/tare to API and various fixes
This commit is contained in:
@@ -3,25 +3,32 @@
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
// Uncomment for Version 2.0 where load cell is connected differently
|
||||
#define _HW_V_20
|
||||
//#define NEW_HEAVY_LOAD_CELL
|
||||
|
||||
// ------------------------------------------ WiFi ---------------------------------------------------------------------------------
|
||||
|
||||
const char *CONFIG_WIFI_SSID = "WLAN";
|
||||
//const char *CONFIG_WIFI_SSID = "WLAN";
|
||||
const char *CONFIG_WIFI_SSID = "RepeaterWZ";
|
||||
const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN";
|
||||
const char *CONFIG_HOSTNAME = "smartswim";
|
||||
|
||||
|
||||
// ------------------------------------- Hardware & Measurement Settings ------------------------------------------------------------
|
||||
|
||||
// Uncomment for Version 2.0 where load cell is connected differently
|
||||
//#define _HW_V_20
|
||||
|
||||
const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in normal phase
|
||||
const uint8_t CONFIG_TARE_AVG_COUNT = 10; // number of measurements in tare-phase (to find 0 )
|
||||
const uint8_t CONFIG_TARE_AVG_COUNT = 20; // number of measurements in tare-phase (to find 0 )
|
||||
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
||||
const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
const uint32_t CONFIG_SESSION_MAX_LENGTH_HOURS = 3; // maximum length of one session
|
||||
const char *CONFIG_DATA_PATH = "/dat"; // folder in SPIFFS file system to store measurement data
|
||||
using MeasurementT = uint16_t; // data type for one measurement
|
||||
#ifdef NEW_HEAVY_LOAD_CELL
|
||||
const int CONFIG_VALUE_DIVIDER = 8; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
#else
|
||||
const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
#endif
|
||||
|
||||
|
||||
// ------------------------------------- Derived Settings -----------------------------------------------------------------------------
|
||||
|
||||
@@ -24,15 +24,25 @@ template <typename SessionT>
|
||||
void httpSetup(SessionManager<SessionT> *sessionManager)
|
||||
{
|
||||
auto cbStartSession = [sessionManager](httpd_req_t *req) {
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, "Session started", -1);
|
||||
sessionManager->startMeasurements();
|
||||
Serial.println("Started session");
|
||||
};
|
||||
auto cbStopSession = [sessionManager](httpd_req_t *req) {
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_send(req, "Session stopped", -1);
|
||||
sessionManager->stopMeasurements();
|
||||
Serial.println("Stopped session");
|
||||
};
|
||||
auto cbRestart = [](httpd_req_t *req) {
|
||||
Serial.println("Restarted requested");
|
||||
ESP.restart();
|
||||
};
|
||||
auto cbTare = [sessionManager](httpd_req_t *req) {
|
||||
Serial.println("Tare");
|
||||
sessionManager->tare();
|
||||
};
|
||||
auto cbStatus = [sessionManager](httpd_req_t *req) {
|
||||
String result;
|
||||
result.reserve(512);
|
||||
@@ -50,6 +60,12 @@ void httpSetup(SessionManager<SessionT> *sessionManager)
|
||||
else
|
||||
result += "{},\n";
|
||||
}
|
||||
// scale
|
||||
{
|
||||
const String tareOffset(sessionManager->tareOffset());
|
||||
const String divider(CONFIG_VALUE_DIVIDER);
|
||||
result += "\"scale\": { \"tare_offset\": " + tareOffset + ", \"divider\":" + divider + "},\n";
|
||||
}
|
||||
// flash
|
||||
{
|
||||
const String usedBytes(portablefs::usedBytes());
|
||||
@@ -74,12 +90,18 @@ void httpSetup(SessionManager<SessionT> *sessionManager)
|
||||
auto cbGetData = [sessionManager](httpd_req_t *req) {
|
||||
auto sessionId = sessionManager->session().getStartTime();
|
||||
uint32_t startIdx = getUrlQueryParameter(req, "startIdx", 0);
|
||||
Serial.printf("Data request, start index: %d", startIdx);
|
||||
//Serial.printf("Data request, start index: %d\n", startIdx);
|
||||
if (startIdx >= sessionManager->session().numMeasurements())
|
||||
{
|
||||
httpd_resp_send_404(req);
|
||||
return;
|
||||
}
|
||||
|
||||
//headers
|
||||
httpd_resp_set_hdr(req, "Content-Type", "application/x-msgpack");
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
httpd_resp_set_hdr(req, "content-disposition", ("attachment; filename=\"" + String(sessionId) + ".st\"").c_str());
|
||||
String contentDisp = "attachment; filename=\"" + String(sessionId) + ".st\"";
|
||||
httpd_resp_set_hdr(req, "content-disposition", contentDisp.c_str());
|
||||
|
||||
//data
|
||||
StreamingMsgPackEncoder<DummyWriter> encoderToDetermineSize(nullptr);
|
||||
@@ -104,7 +126,8 @@ void httpSetup(SessionManager<SessionT> *sessionManager)
|
||||
|
||||
espHttpServer.on("/api/session/data", HTTP_GET, cbGetData);
|
||||
espHttpServer.on("/api/status", HTTP_GET, cbStatus);
|
||||
|
||||
espHttpServer.on("/api/tare", HTTP_GET, cbTare);
|
||||
espHttpServer.on("/api/restart", HTTP_GET, cbRestart);
|
||||
auto webdav = webdavHandler("/webdav/", "/dat");
|
||||
espHttpServer.on("/webdav/*?", HTTP_GET, webdav);
|
||||
espHttpServer.on("/webdav/*?", HTTP_PROPFIND, webdav);
|
||||
|
||||
Reference in New Issue
Block a user