Simpler Measurement session, fully in memory
This commit is contained in:
@@ -2,13 +2,12 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
//#define _HW_V_20
|
||||
|
||||
// HX711 load cell
|
||||
#ifdef PLATFORM_ESP32
|
||||
|
||||
#ifdef _HW_V_20
|
||||
#ifdef _HW_V_20
|
||||
const int CONFIG_SCALE_DOUT_PIN = 23;
|
||||
const int CONFIG_SCALE_SCK_PIN = 22;
|
||||
#else
|
||||
@@ -20,10 +19,15 @@ const int CONFIG_SCALE_SCK_PIN = 23;
|
||||
const int CONFIG_SCALE_DOUT_PIN = D2;
|
||||
const int CONFIG_SCALE_SCK_PIN = D3;
|
||||
#endif
|
||||
const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in normal phase
|
||||
const uint8_t CONFIG_TARE_AVG_COUNT = 6; // number of measurements in tare-phase (to find 0 )
|
||||
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
||||
const uint8_t CONFIG_MEASUREMENT_AVG_COUNT = 1; // number of measurements in normal phase
|
||||
const uint8_t CONFIG_TARE_AVG_COUNT = 6; // 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 = 8; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t
|
||||
|
||||
const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024; //1024*8 - 16 * sizeof(uint32_t);
|
||||
|
||||
const uint32_t CONFIG_SESSION_MAX_LENGTH_HOURS = 1;
|
||||
const uint32_t CONFIG_SESSION_MAX_SIZE = CONFIG_SESSION_MAX_LENGTH_HOURS * 3600 * (1000 / CONFIG_MEASURE_DELAY) * sizeof(uint16_t);
|
||||
|
||||
const char *CONFIG_DATA_PATH = "/dat";
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "MeasurementSession.h"
|
||||
#include "SpiffsStorage.h"
|
||||
#include "DeviceInfoLog.h"
|
||||
#include "SimpleMeasurementSession.h"
|
||||
|
||||
// Configuration
|
||||
#include "ConfigWifi.h"
|
||||
@@ -29,7 +30,8 @@
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "pool.ntp.org");
|
||||
|
||||
typedef MeasurementSession<uint16_t, SpiffsStorageReader, SpiffsStorageWriter, CONFIG_SESSION_CHUNK_SIZE> Session_T;
|
||||
//typedef MeasurementSession<uint16_t, SpiffsStorageReader, SpiffsStorageWriter, CONFIG_SESSION_CHUNK_SIZE> Session_T;
|
||||
using Session_T = SimpleMeasurementSession<uint16_t, CONFIG_SESSION_MAX_SIZE>;
|
||||
|
||||
template <typename Session_T>
|
||||
class SessionManager
|
||||
@@ -46,6 +48,7 @@ public:
|
||||
scale.tare(CONFIG_TARE_AVG_COUNT);
|
||||
Serial.println("Finished tare");
|
||||
session.init(timeClient.getEpochTime());
|
||||
Serial.println("Finished session init");
|
||||
}
|
||||
|
||||
void startMeasurements()
|
||||
@@ -69,13 +72,16 @@ public:
|
||||
void iteration()
|
||||
{
|
||||
if (!measuring_)
|
||||
{
|
||||
//Serial.println("Disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t measurement = -1;
|
||||
scale.measure(measurement);
|
||||
session.addPoint(measurement);
|
||||
bool addPointSuccessful = session.addPoint(measurement);
|
||||
if(!addPointSuccessful) {
|
||||
Serial.println("Maximum time of session reached - stopping");
|
||||
stopMeasurements();
|
||||
return;
|
||||
}
|
||||
Serial.print("Measurement: ");
|
||||
Serial.println(measurement);
|
||||
if (lastCallTime_ != 0)
|
||||
@@ -198,9 +204,11 @@ void httpSetup(SessionManager<Session_T> *sessionManager)
|
||||
espHttpServer.on("/api/session/data", HTTP_GET, cbGetData);
|
||||
espHttpServer.on("/api/status", HTTP_GET, cbStatus);
|
||||
|
||||
espHttpServer.on("/webdav/*?", HTTP_GET, webdavHandler);
|
||||
espHttpServer.on("/webdav/*?", HTTP_PROPFIND, webdavHandler);
|
||||
espHttpServer.on("/webdav/*?", HTTP_DELETE, webdavHandler);
|
||||
auto webdav = webdavHandler("/webdav/", "/dat");
|
||||
espHttpServer.on("/webdav/*?", HTTP_GET, webdav);
|
||||
espHttpServer.on("/webdav/*?", HTTP_PROPFIND, webdav);
|
||||
espHttpServer.on("/webdav/*?", HTTP_DELETE, webdav);
|
||||
Serial.println("HTTP setup done");
|
||||
}
|
||||
|
||||
void setup()
|
||||
@@ -258,6 +266,5 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(10000);
|
||||
//sessionManager.iteration();
|
||||
sessionManager.iteration();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user